mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Fixes a loop in the c-parser, bug 273759.
This commit is contained in:
parent
7784c9c727
commit
b65a792506
3 changed files with 24 additions and 3 deletions
|
@ -242,4 +242,22 @@ public class FaultToleranceTests extends AST2BaseTest {
|
|||
IASTSimpleDeclaration s= getDeclaration(ct, 2);
|
||||
assertEquals("int i;", s.getRawSignature());
|
||||
}
|
||||
|
||||
|
||||
// #define XX() .
|
||||
// int c;
|
||||
// XX(
|
||||
// );
|
||||
// int d;
|
||||
public void testErrorRecovery_273759() throws Exception {
|
||||
IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.C, false, false);
|
||||
IASTSimpleDeclaration s= getDeclaration(tu, 0);
|
||||
IASTProblemDeclaration p= getDeclaration(tu, 1);
|
||||
s= getDeclaration(tu, 2);
|
||||
|
||||
tu= parse(getAboveComment(), ParserLanguage.CPP, false, false);
|
||||
s= getDeclaration(tu, 0);
|
||||
p= getDeclaration(tu, 1);
|
||||
s= getDeclaration(tu, 2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1539,8 +1539,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
// a node was detected by assuming additional tokens (e.g. missing semicolon)
|
||||
IASTNode n= bt.getNodeBeforeProblem();
|
||||
if (n instanceof IASTDeclaration) {
|
||||
declarationMark= null;
|
||||
return new IASTDeclaration[] {(IASTDeclaration) n, buildProblemDeclaration(origProblem)};
|
||||
IToken la1= LAcatchEOF(1);
|
||||
if (la1 == null || la1.getOffset() > offset) {
|
||||
declarationMark= null;
|
||||
return new IASTDeclaration[] {(IASTDeclaration) n, buildProblemDeclaration(origProblem)};
|
||||
}
|
||||
}
|
||||
|
||||
if (declarationMark != null && isActiveCode()) {
|
||||
|
|
|
@ -389,7 +389,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
endOffset= figureEndOffset(declSpec, declarators);
|
||||
break;
|
||||
default:
|
||||
if (declOption != DeclarationOptions.LOCAL) {
|
||||
if (declOption != DeclarationOptions.LOCAL && endOffset != firstOffset) {
|
||||
insertSemi= true;
|
||||
if (markBeforDtor != null && !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) {
|
||||
backup(markBeforDtor);
|
||||
|
|
Loading…
Add table
Reference in a new issue