mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bogus syntax errors, bug 295064.
This commit is contained in:
parent
c5d05dd874
commit
30e6d3f933
2 changed files with 35 additions and 6 deletions
|
@ -7713,5 +7713,25 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
final String code = getAboveComment();
|
||||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||
}
|
||||
|
||||
// void test() {
|
||||
// int x,y;
|
||||
// return y < x ? -1 : y > x ? 1 : 0;
|
||||
// }
|
||||
public void testSyntax1_295064() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||
}
|
||||
|
||||
// typedef int TInt;
|
||||
// template <typename T> class CT {
|
||||
// CT(TInt);
|
||||
// };
|
||||
// template <typename T> inline CT<T>::CT(TInt) {}
|
||||
public void testSyntax2_295064() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -595,6 +595,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
lt1= LT(1);
|
||||
switch(lt1) {
|
||||
case IToken.tQUESTION:
|
||||
if (onTopOfTemplateArgs && rejectLogicalOperatorInTemplateID > 0) {
|
||||
throwBacktrack(LA(1));
|
||||
}
|
||||
conditionCount++;
|
||||
// <logical-or> ? <expression> : <assignment-expression>
|
||||
// Precedence: 25 is lower than precedence of logical or; 1 is lower than precedence of expression
|
||||
|
@ -1766,7 +1769,17 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
case IToken.t_try:
|
||||
case IToken.tCOLON:
|
||||
case IToken.tLBRACE:
|
||||
return functionDefinition(firstOffset, declSpec, declarators);
|
||||
if (declarators.length != 1)
|
||||
throwBacktrack(LA(1));
|
||||
|
||||
dtor= declarators[0];
|
||||
if (altDeclSpec != null && altDtor != null && dtor != null &&
|
||||
!(ASTQueries.findTypeRelevantDeclarator(dtor) instanceof IASTFunctionDeclarator)) {
|
||||
declSpec= altDeclSpec;
|
||||
dtor= altDtor;
|
||||
}
|
||||
return functionDefinition(firstOffset, declSpec, dtor);
|
||||
|
||||
default:
|
||||
if (declOption != DeclarationOptions.LOCAL) {
|
||||
insertSemi= true;
|
||||
|
@ -1817,12 +1830,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
|
||||
private IASTDeclaration functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec,
|
||||
IASTDeclarator[] dtors) throws EndOfFileException, BacktrackException {
|
||||
IASTDeclarator outerDtor) throws EndOfFileException, BacktrackException {
|
||||
|
||||
if (dtors.length != 1)
|
||||
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
||||
|
||||
final IASTDeclarator outerDtor= dtors[0];
|
||||
final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(outerDtor);
|
||||
if (dtor instanceof ICPPASTFunctionDeclarator == false)
|
||||
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
||||
|
|
Loading…
Add table
Reference in a new issue