mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Bug 488265 - Syntax error lambda with capture in initializer list
Change-Id: I5505a47d33317287b0463e06eaf84ec0067b9e46
This commit is contained in:
parent
2b53f9eae3
commit
d6611cfcfa
2 changed files with 59 additions and 26 deletions
|
@ -8533,6 +8533,18 @@ public class AST2CPPTests extends AST2TestBase {
|
||||||
parseAndCheckBindings();
|
parseAndCheckBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// void f(T p);
|
||||||
|
//
|
||||||
|
// class A {
|
||||||
|
// void m() {
|
||||||
|
// f([this] (int x) {});
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
public void testLambdaWithCapture() throws Exception {
|
||||||
|
parseAndCheckBindings();
|
||||||
|
}
|
||||||
|
|
||||||
// int foo = 0;
|
// int foo = 0;
|
||||||
// auto bar = [foo] { return foo; };
|
// auto bar = [foo] { return foo; };
|
||||||
public void testLambdaWithCapture_446225() throws Exception {
|
public void testLambdaWithCapture_446225() throws Exception {
|
||||||
|
@ -8544,14 +8556,25 @@ public class AST2CPPTests extends AST2TestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// template<typename T>
|
// template<typename T>
|
||||||
// void f(T p);
|
// class B;
|
||||||
//
|
//
|
||||||
// class A {
|
// template<typename T, typename... U>
|
||||||
// void m() {
|
// struct B<T(U...)> {
|
||||||
// f([this] (int x) {});
|
// template<typename V>
|
||||||
// }
|
// B(V);
|
||||||
// };
|
// };
|
||||||
public void testLambdaWithCapture() throws Exception {
|
//
|
||||||
|
// struct A {
|
||||||
|
// B<bool(int arg)> f;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// void waldo(A a);
|
||||||
|
//
|
||||||
|
// void test() {
|
||||||
|
// int p;
|
||||||
|
// waldo({[p](int arg) { return true; }});
|
||||||
|
// }
|
||||||
|
public void testLambdaWithCaptureInInitializerList_488265() throws Exception {
|
||||||
parseAndCheckBindings();
|
parseAndCheckBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8582,7 +8605,6 @@ public class AST2CPPTests extends AST2TestBase {
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
// S::S(int a) : f{a} {} // Member initializer
|
// S::S(int a) : f{a} {} // Member initializer
|
||||||
|
|
||||||
public void testInitSyntax_302412() throws Exception {
|
public void testInitSyntax_302412() throws Exception {
|
||||||
parseAndCheckBindings();
|
parseAndCheckBindings();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2856,7 +2856,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
private ICPPASTFunctionDefinition functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec,
|
private ICPPASTFunctionDefinition functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec,
|
||||||
IASTDeclarator outerDtor) throws EndOfFileException, BacktrackException {
|
IASTDeclarator outerDtor) throws EndOfFileException, BacktrackException {
|
||||||
|
|
||||||
final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(outerDtor);
|
final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(outerDtor);
|
||||||
if (!(dtor instanceof ICPPASTFunctionDeclarator))
|
if (!(dtor instanceof ICPPASTFunctionDeclarator))
|
||||||
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
||||||
|
@ -3985,7 +3984,36 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
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= allowDesignators ? designatorList() : null;
|
List<ICPPASTDesignator> designators = null;
|
||||||
|
IToken mark = mark();
|
||||||
|
if (allowDesignators) {
|
||||||
|
designators= designatorList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (designators != null) {
|
||||||
|
try {
|
||||||
|
ICPPASTDesignatedInitializer desigInitializer = getNodeFactory().newDesignatedInitializer(null);
|
||||||
|
setRange(desigInitializer, designators.get(0));
|
||||||
|
for (ICPPASTDesignator d : designators) {
|
||||||
|
desigInitializer.addDesignator(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LT(1) != IToken.tEOC) {
|
||||||
|
// GNU extension: the assign operator is optional.
|
||||||
|
if (LT(1) == IToken.tASSIGN)
|
||||||
|
consume(IToken.tASSIGN);
|
||||||
|
|
||||||
|
ICPPASTInitializerClause clause= initClause(false);
|
||||||
|
desigInitializer.setOperand(clause);
|
||||||
|
adjustLength(desigInitializer, clause);
|
||||||
|
}
|
||||||
|
result.add(desigInitializer);
|
||||||
|
} catch (BacktrackException e) {
|
||||||
|
backup(mark);
|
||||||
|
designators = null; // Retry without designators.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -4007,23 +4035,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.add(clause);
|
result.add(clause);
|
||||||
} else {
|
|
||||||
ICPPASTDesignatedInitializer desigInitializer = getNodeFactory().newDesignatedInitializer(null);
|
|
||||||
setRange(desigInitializer, designators.get(0));
|
|
||||||
for (ICPPASTDesignator d : designators) {
|
|
||||||
desigInitializer.addDesignator(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LT(1) != IToken.tEOC) {
|
|
||||||
// GNU extension: the assign operator is optional.
|
|
||||||
if (LT(1) == IToken.tASSIGN)
|
|
||||||
consume(IToken.tASSIGN);
|
|
||||||
|
|
||||||
ICPPASTInitializerClause clause= initClause(false);
|
|
||||||
desigInitializer.setOperand(clause);
|
|
||||||
adjustLength(desigInitializer, clause);
|
|
||||||
}
|
|
||||||
result.add(desigInitializer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LT(1) != IToken.tCOMMA)
|
if (LT(1) != IToken.tCOMMA)
|
||||||
|
|
Loading…
Add table
Reference in a new issue