1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

fix bug 74069: [Parser][IProblem] if (…) if (…) else if (…) causes unnecessary warning marker

This commit is contained in:
Andrew Niefer 2004-10-21 16:15:45 +00:00
parent bd562b731b
commit 8e22cf635e
2 changed files with 68 additions and 42 deletions

View file

@ -2300,5 +2300,29 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
assertEquals( IProblem.SYNTAX_ERROR, problem.getID() );
assertFalse( i.hasNext() );
}
public void testBug74069() throws Exception{
Writer writer = new StringWriter();
writer.write( "int f() { \n"); //$NON-NLS-1$
writer.write( " int a, b, c; \n"); //$NON-NLS-1$
writer.write( " if( a < b ) \n"); //$NON-NLS-1$
writer.write( " if( b < c ) \n"); //$NON-NLS-1$
writer.write( " return b; \n"); //$NON-NLS-1$
writer.write( " else if ( a < c ) \n"); //$NON-NLS-1$
writer.write( " return c; \n"); //$NON-NLS-1$
writer.write( " else \n"); //$NON-NLS-1$
writer.write( " return a; \n"); //$NON-NLS-1$
writer.write( " else if( a < c ) \n"); //$NON-NLS-1$
writer.write( " return a; \n"); //$NON-NLS-1$
writer.write( " else if( b < c ) \n"); //$NON-NLS-1$
writer.write( " return c; \n"); //$NON-NLS-1$
writer.write( " else \n"); //$NON-NLS-1$
writer.write( " return b; \n"); //$NON-NLS-1$
writer.write( "} \n"); //$NON-NLS-1$
parse( writer.toString() );
Iterator i = callback.getProblems();
assertFalse( i.hasNext() );
}
}

View file

@ -5883,6 +5883,7 @@ public class Parser implements IParserData, IParser
cleanupLastToken();
return;
case IToken.t_if :
if_loop: while( true ){
consume(IToken.t_if);
consume(IToken.tLPAREN);
IToken start = LA(1);
@ -5916,14 +5917,15 @@ public class Parser implements IParserData, IParser
if (LT(1) == IToken.t_else) {
consume(IToken.t_else);
if (LT(1) == IToken.t_if) {
//an else if, return and get the rest of the else if as
// the next statement instead of recursing
//an else if, don't recurse, just loop and do another if
cleanupLastToken();
return;
continue if_loop;
} else if (LT(1) != IToken.tLBRACE)
singleStatementScope(scope);
else
statement(scope);
}
break if_loop;
}
cleanupLastToken();
return;