mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 02:05:39 +02:00
Bug 406462 - Fixed a regression in parsing of lambda expressions.
The regression was triggered by the change that introduced support for designated initializers in C++. Change-Id: I8e78a8818b8365cce0b878cd4a2c19116b3682d4
This commit is contained in:
parent
f0bd13a754
commit
2af5429bdb
2 changed files with 27 additions and 14 deletions
|
@ -8516,6 +8516,18 @@ public class AST2CPPTests extends AST2TestBase {
|
||||||
assertEquals(2, bh.getTranslationUnit().getReferences(foo1).length);
|
assertEquals(2, bh.getTranslationUnit().getReferences(foo1).length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// void f(T p);
|
||||||
|
//
|
||||||
|
// class A {
|
||||||
|
// void m() {
|
||||||
|
// f([this] (int x) {});
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
public void testLambdaWithCapture() throws Exception {
|
||||||
|
parseAndCheckBindings();
|
||||||
|
}
|
||||||
|
|
||||||
// typedef int TInt;
|
// typedef int TInt;
|
||||||
// void test() {
|
// void test() {
|
||||||
// int a1= {}, a2{}; // Initializer for declarator
|
// int a1= {}, a2{}; // Initializer for declarator
|
||||||
|
|
|
@ -1104,7 +1104,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
stopWithNextOperator= true;
|
stopWithNextOperator= true;
|
||||||
} else if (allowBraceInitializer && LT(1) == IToken.tLBRACE) {
|
} else if (allowBraceInitializer && LT(1) == IToken.tLBRACE) {
|
||||||
// Brace initializer
|
// Brace initializer
|
||||||
expr= bracedInitList(true);
|
expr= bracedInitList(true, false);
|
||||||
lt1= LT(1);
|
lt1= LT(1);
|
||||||
if (lt1 != IToken.tCOLON && lt1 != IToken.tCOMMA)
|
if (lt1 != IToken.tCOLON && lt1 != IToken.tCOMMA)
|
||||||
stopWithNextOperator= true;
|
stopWithNextOperator= true;
|
||||||
|
@ -1638,7 +1638,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTTypeId t= typeId(DeclarationOptions.TYPEID);
|
IASTTypeId t= typeId(DeclarationOptions.TYPEID);
|
||||||
consume(IToken.tRPAREN);
|
consume(IToken.tRPAREN);
|
||||||
if (LT(1) == IToken.tLBRACE) {
|
if (LT(1) == IToken.tLBRACE) {
|
||||||
IASTInitializer i = bracedInitList(false);
|
IASTInitializer i = bracedInitList(false, false);
|
||||||
firstExpression= getNodeFactory().newTypeIdInitializerExpression(t, i);
|
firstExpression= getNodeFactory().newTypeIdInitializerExpression(t, i);
|
||||||
setRange(firstExpression, offset, calculateEndOffset(i));
|
setRange(firstExpression, offset, calculateEndOffset(i));
|
||||||
break;
|
break;
|
||||||
|
@ -1701,7 +1701,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
consume(IToken.tLBRACKET);
|
consume(IToken.tLBRACKET);
|
||||||
IASTInitializerClause expression;
|
IASTInitializerClause expression;
|
||||||
if (LT(1) == IToken.tLBRACE) {
|
if (LT(1) == IToken.tLBRACE) {
|
||||||
expression= bracedInitList(false);
|
expression= bracedInitList(false, false);
|
||||||
} else {
|
} else {
|
||||||
expression= expression();
|
expression= expression();
|
||||||
}
|
}
|
||||||
|
@ -3824,7 +3824,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
// braced-init-list
|
// braced-init-list
|
||||||
if (option.fAllowBracedInitializer && lt1 == IToken.tLBRACE) {
|
if (option.fAllowBracedInitializer && lt1 == IToken.tLBRACE) {
|
||||||
return bracedInitList(false);
|
return bracedInitList(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ( expression-list )
|
// ( expression-list )
|
||||||
|
@ -3844,7 +3844,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (lt1 == IToken.tLPAREN) {
|
if (lt1 == IToken.tLPAREN) {
|
||||||
return ctorStyleInitializer(true);
|
return ctorStyleInitializer(true);
|
||||||
}
|
}
|
||||||
return bracedInitList(false);
|
return bracedInitList(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3867,7 +3867,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ICPPASTInitializerClause> expressionList() throws EndOfFileException, BacktrackException {
|
private List<ICPPASTInitializerClause> expressionList() throws EndOfFileException, BacktrackException {
|
||||||
return initializerList(false);
|
return initializerList(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3879,7 +3879,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
BacktrackException {
|
BacktrackException {
|
||||||
// braced-init-list
|
// braced-init-list
|
||||||
if (LT(1) == IToken.tLBRACE) {
|
if (LT(1) == IToken.tLBRACE) {
|
||||||
return bracedInitList(allowSkipping);
|
return bracedInitList(allowSkipping, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// assignment expression
|
// assignment expression
|
||||||
|
@ -3893,7 +3893,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
* { initializer-list ,opt }
|
* { initializer-list ,opt }
|
||||||
* { }
|
* { }
|
||||||
*/
|
*/
|
||||||
private ICPPASTInitializerList bracedInitList(boolean allowSkipping) throws EndOfFileException, BacktrackException {
|
private ICPPASTInitializerList bracedInitList(boolean allowSkipping, boolean allowDesignators)
|
||||||
|
throws EndOfFileException, BacktrackException {
|
||||||
int offset = consume(IToken.tLBRACE).getOffset();
|
int offset = consume(IToken.tLBRACE).getOffset();
|
||||||
|
|
||||||
// { }
|
// { }
|
||||||
|
@ -3902,7 +3903,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// { initializer-list ,opt }
|
// { initializer-list ,opt }
|
||||||
List<ICPPASTInitializerClause> initList= initializerList(allowSkipping);
|
List<ICPPASTInitializerClause> initList= initializerList(allowSkipping, allowDesignators);
|
||||||
if (LT(1) == IToken.tCOMMA)
|
if (LT(1) == IToken.tCOMMA)
|
||||||
consume();
|
consume();
|
||||||
|
|
||||||
|
@ -3919,12 +3920,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
* initializer-clause ...opt
|
* initializer-clause ...opt
|
||||||
* initializer-list , initializer-clause ...opt
|
* initializer-list , initializer-clause ...opt
|
||||||
*/
|
*/
|
||||||
private List<ICPPASTInitializerClause> initializerList(boolean allowSkipping) throws EndOfFileException,
|
private List<ICPPASTInitializerClause> initializerList(boolean allowSkipping, boolean allowDesignators)
|
||||||
BacktrackException {
|
throws EndOfFileException, BacktrackException {
|
||||||
List<ICPPASTInitializerClause> result= new ArrayList<>();
|
List<ICPPASTInitializerClause> result= new ArrayList<>();
|
||||||
// List of initializer clauses
|
// List of initializer clauses
|
||||||
loop: while (true) {
|
loop: while (true) {
|
||||||
List<ICPPASTDesignator> designators= designatorList();
|
List<ICPPASTDesignator> designators= allowDesignators ? designatorList() : null;
|
||||||
if (designators == null) {
|
if (designators == null) {
|
||||||
// Clause may be null, add to initializer anyways, so that the size can be computed.
|
// Clause may be null, add to initializer anyways, so that the size can be computed.
|
||||||
ICPPASTInitializerClause clause = initClause(allowSkipping);
|
ICPPASTInitializerClause clause = initClause(allowSkipping);
|
||||||
|
@ -5249,7 +5250,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
case IToken.tEOC:
|
case IToken.tEOC:
|
||||||
break;
|
break;
|
||||||
case IToken.tLBRACE:
|
case IToken.tLBRACE:
|
||||||
init= bracedInitList(false);
|
init= bracedInitList(false, false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
init= expression();
|
init= expression();
|
||||||
|
@ -5296,7 +5297,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTInitializerClause expr = null;
|
IASTInitializerClause expr = null;
|
||||||
final int lt1 = LT(1);
|
final int lt1 = LT(1);
|
||||||
if (lt1 == IToken.tLBRACE) {
|
if (lt1 == IToken.tLBRACE) {
|
||||||
expr= bracedInitList(true);
|
expr= bracedInitList(true, false);
|
||||||
} else if (lt1 != IToken.tSEMI) {
|
} else if (lt1 != IToken.tSEMI) {
|
||||||
expr = expression();
|
expr = expression();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue