1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Fixes a loop in the c-parser, bug 273759.

This commit is contained in:
Markus Schorn 2009-04-27 08:32:31 +00:00
parent 7784c9c727
commit b65a792506
3 changed files with 24 additions and 3 deletions

View file

@ -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);
}
}

View file

@ -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()) {

View file

@ -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);