1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixed Bug 104800 Null-statement terminates a do-statement

This commit is contained in:
John Camelon 2005-07-22 15:10:56 +00:00
parent 16118927ca
commit 906b67ad17
3 changed files with 34 additions and 0 deletions

View file

@ -5087,4 +5087,16 @@ public class AST2CPPTests extends AST2BaseTest {
IASTExpressionStatement es = (IASTExpressionStatement) labelStmt.getNestedStatement();
assertTrue( es.getExpression() instanceof IASTUnaryExpression );
}
public void testBug104800() throws Exception {
StringBuffer buffer = new StringBuffer( "int f() { \n"); //$NON-NLS-1$
buffer.append( "int i;\n"); //$NON-NLS-1$
buffer.append( "do { ++i; } while( i < 10 );\n"); //$NON-NLS-1$
buffer.append( "return 0;\n"); //$NON-NLS-1$
buffer.append ( "}\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parseAndCheckBindings( buffer.toString() );
IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
IASTCompoundStatement body = (IASTCompoundStatement) f.getBody();
assertEquals( body.getStatements().length, 3 );
}
}

View file

@ -3355,4 +3355,16 @@ public class AST2Tests extends AST2BaseTest {
assertSame( x2, col.getName(4).resolveBinding() );
assertTrue( col.getName(3).resolveBinding() instanceof ILabel );
}
public void testBug104800() throws Exception {
StringBuffer buffer = new StringBuffer( "int f() { \n"); //$NON-NLS-1$
buffer.append( "int i;\n"); //$NON-NLS-1$
buffer.append( "do { ++i; } while( i < 10 );\n"); //$NON-NLS-1$
buffer.append( "return 0;\n"); //$NON-NLS-1$
buffer.append ( "}\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parseAndCheckBindings( buffer.toString() );
IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
IASTCompoundStatement body = (IASTCompoundStatement) f.getBody();
assertEquals( body.getStatements().length, 3 );
}
}

View file

@ -1844,12 +1844,22 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
int lastOffset;
switch (LT(1)) {
case IToken.tRPAREN:
case IToken.tEOC:
consume();
break;
default:
throw backtrack;
}
switch (LT(1)) {
case IToken.tSEMI:
case IToken.tEOC:
lastOffset = consume().getEndOffset();
break;
default:
throw backtrack;
}
IASTDoStatement do_statement = createDoStatement();
((ASTNode) do_statement).setOffsetAndLength(startOffset, lastOffset