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:
parent
16118927ca
commit
906b67ad17
3 changed files with 34 additions and 0 deletions
|
@ -5087,4 +5087,16 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
IASTExpressionStatement es = (IASTExpressionStatement) labelStmt.getNestedStatement();
|
IASTExpressionStatement es = (IASTExpressionStatement) labelStmt.getNestedStatement();
|
||||||
assertTrue( es.getExpression() instanceof IASTUnaryExpression );
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3355,4 +3355,16 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertSame( x2, col.getName(4).resolveBinding() );
|
assertSame( x2, col.getName(4).resolveBinding() );
|
||||||
assertTrue( col.getName(3).resolveBinding() instanceof ILabel );
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1844,6 +1844,15 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
int lastOffset;
|
int lastOffset;
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case IToken.tRPAREN:
|
case IToken.tRPAREN:
|
||||||
|
case IToken.tEOC:
|
||||||
|
consume();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw backtrack;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (LT(1)) {
|
||||||
|
case IToken.tSEMI:
|
||||||
case IToken.tEOC:
|
case IToken.tEOC:
|
||||||
lastOffset = consume().getEndOffset();
|
lastOffset = consume().getEndOffset();
|
||||||
break;
|
break;
|
||||||
|
@ -1851,6 +1860,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
throw backtrack;
|
throw backtrack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IASTDoStatement do_statement = createDoStatement();
|
IASTDoStatement do_statement = createDoStatement();
|
||||||
((ASTNode) do_statement).setOffsetAndLength(startOffset, lastOffset
|
((ASTNode) do_statement).setOffsetAndLength(startOffset, lastOffset
|
||||||
- startOffset);
|
- startOffset);
|
||||||
|
|
Loading…
Add table
Reference in a new issue