diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 56c4cd6133e..588efc8aaad 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -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 ); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 66348f75327..eab89b845ea 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -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 ); + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 74edec59c48..7c4f88023ac 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -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