diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java index 16e644d5b9d..f2f52a2f8f4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java @@ -801,8 +801,10 @@ public class CompleteParseBaseTest extends TestCase ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), //$NON-NLS-1$ ParserMode.COMPLETE_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.COMPLETE_PARSE, language, null ); - if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ - assertTrue( ((CompleteParser)parser).validateCaches()); + boolean parseResult = parser.parse(); + if( ! parseResult && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ + if( parseResult ) + assertTrue( ((CompleteParser)parser).validateCaches()); return callback.getCompilationUnit(); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseProblemTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseProblemTest.java index 8ec6b548599..1e404a79aaa 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseProblemTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseProblemTest.java @@ -58,8 +58,21 @@ public class CompleteParseProblemTest extends CompleteParseBaseTest { assertEquals( p.getID(), IProblem.SYNTAX_ERROR ); assertEquals( p.getSourceStart(), code.indexOf( name )); //$NON-NLS-1$ assertEquals( p.getSourceEnd(), code.indexOf( name ) + name.length() ); //$NON-NLS-1$ + } + + public void testBug68306() throws Exception + { + StringBuffer buffer = new StringBuffer(); + buffer.append( "class Foo { int bar( int ); };\n" ); //$NON-NLS-1$ + buffer.append( "int Foo::bar( int ){}\n" ); //$NON-NLS-1$ + buffer.append( "int Foo::bar( int ){} //error\n" ); //$NON-NLS-1$ + String code = buffer.toString(); + parse( code, false ); + assertFalse( callback.problems.isEmpty() ); + assertEquals( callback.problems.size(), 1 ); + IProblem p = (IProblem) callback.problems.get( 0 ); + assertTrue( p.checkCategory( IProblem.SEMANTICS_RELATED )); } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index 7a8dff23c0b..df58e350e0c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -881,6 +881,8 @@ public abstract class Parser extends ExpressionParser implements IParser throws EndOfFileException, BacktrackException { simpleDeclarationMark = mark(); + IProblem firstFailure = null; + IProblem secondFailure = null; try { return simpleDeclaration( @@ -893,6 +895,7 @@ public abstract class Parser extends ExpressionParser implements IParser { if( simpleDeclarationMark == null ) throwBacktrack( bt ); + firstFailure = bt.getProblem(); // did not work backup(simpleDeclarationMark); @@ -906,8 +909,14 @@ public abstract class Parser extends ExpressionParser implements IParser catch( BacktrackException bt2 ) { if( simpleDeclarationMark == null ) - throwBacktrack(bt2); - + { + if( firstFailure != null && (bt2.getProblem() == null )) + throwBacktrack(firstFailure); + else + throwBacktrack(bt2); + } + + secondFailure = bt2.getProblem(); backup( simpleDeclarationMark ); try @@ -920,7 +929,13 @@ public abstract class Parser extends ExpressionParser implements IParser catch( BacktrackException b3 ) { backup( simpleDeclarationMark ); //TODO - necessary? - throwBacktrack( b3 ); + + if( firstFailure != null ) + throwBacktrack( firstFailure ); + else if( secondFailure != null ) + throwBacktrack( secondFailure ); + else + throwBacktrack( b3 ); return null; } }