Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarco Stornelli2020-03-01 08:15:11 +0000
committerMarco Stornelli2020-03-13 10:45:49 +0000
commitf150522ad4dad9730d9b9acd1c887698a03b02f2 (patch)
treeabcf2c0fc9798421fe0d070934631d8c3395274a /core
parentbcb955a32104da02f3748dd3ef080cbcb43c646b (diff)
downloadorg.eclipse.cdt-f150522ad4dad9730d9b9acd1c887698a03b02f2.tar.gz
org.eclipse.cdt-f150522ad4dad9730d9b9acd1c887698a03b02f2.tar.xz
org.eclipse.cdt-f150522ad4dad9730d9b9acd1c887698a03b02f2.zip
Bug 560483 - Add support for c++17 constexpr lambda expressions
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/LambdaExpressionTests.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java16
4 files changed, 46 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/LambdaExpressionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/LambdaExpressionTests.java
index 398a6ef19c9..f1552bbc02b 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/LambdaExpressionTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx17/LambdaExpressionTests.java
@@ -50,4 +50,12 @@ public class LambdaExpressionTests extends AST2CPPTestBase {
public void testLambdaCaptures_535196_3() throws Exception {
parseAndCheckBindings();
}
+
+ //int main() {
+ // auto f = []() constexpr {return 2;};
+ // return 0;
+ //}
+ public void testLambdaConstexpr_560483() throws Exception {
+ parseAndCheckBindings();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java
index 3a6d6a297a8..42240ac7f97 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java
@@ -102,6 +102,18 @@ public interface ICPPASTFunctionDeclarator
public void setMutable(boolean value);
/**
+ * When used as a lambda declarator, it can be constexpr.
+ * @since 6.11
+ */
+ public boolean isConstexpr();
+
+ /**
+ * When used as a lambda declarator, it can be constexpr.
+ * @since 6.11
+ */
+ public void setConstexpr(boolean value);
+
+ /**
* Is the method pure virtual?
*/
public boolean isPureVirtual();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java
index c5a448159c7..c5635490efd 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDeclarator.java
@@ -54,6 +54,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
private boolean isConst;
private boolean isMutable;
private RefQualifier refQualifier;
+ private boolean isConstexpr;
private ICPPFunctionScope scope;
@@ -78,6 +79,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
copy.isConst = isConst;
copy.isMutable = isMutable;
copy.refQualifier = refQualifier;
+ copy.isConstexpr = isConstexpr;
for (IASTParameterDeclaration param : getParameters()) {
copy.addParameterDeclaration(param == null ? null : param.copy(style));
@@ -404,4 +406,15 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
}
return null;
}
+
+ @Override
+ public boolean isConstexpr() {
+ return isConstexpr;
+ }
+
+ @Override
+ public void setConstexpr(boolean value) {
+ assertNotFrozen();
+ this.isConstexpr = value;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index 6e04ad4ac2f..227f8699cb2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -4806,9 +4806,19 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
// cv-qualifiers
if (isLambdaDeclarator) {
- if (LT(1) == IToken.t_mutable) {
- fc.setMutable(true);
- endOffset = consume().getEndOffset();
+ specloop: while (true) {
+ switch (LT(1)) {
+ case IToken.t_mutable:
+ fc.setMutable(true);
+ endOffset = consume().getEndOffset();
+ break;
+ case IToken.t_constexpr:
+ fc.setConstexpr(true);
+ endOffset = consume().getEndOffset();
+ break;
+ default:
+ break specloop;
+ }
}
} else {
cvloop: while (true) {

Back to the top