Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2018-11-29 03:41:32 +0000
committerNathan Ridge2018-11-29 22:40:20 +0000
commit586ccf790bf9f12aebbce7057115857455fe42f7 (patch)
treedcb6987ab6dcd73484ab449ed850be722a563998
parent9e44f3634abf8e22f1950e7e10e464ccc2adbe86 (diff)
downloadorg.eclipse.cdt-586ccf790bf9f12aebbce7057115857455fe42f7.tar.gz
org.eclipse.cdt-586ccf790bf9f12aebbce7057115857455fe42f7.tar.xz
org.eclipse.cdt-586ccf790bf9f12aebbce7057115857455fe42f7.zip
Bug 541670 - constexpr implies toplevel const
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java5
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticTestBase.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java4
3 files changed, 17 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index 3ec4cf786d3..d1ee11ec350 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -11627,6 +11627,11 @@ public class AST2CPPTests extends AST2CPPTestBase {
assertSameType(waldo2.getType(), CommonCPPTypes.constInt);
}
+ // constexpr int* waldo;
+ public void testConstexprPointerVariable_541670() throws Exception {
+ getAssertionHelper().assertVariableType("waldo", CommonCPPTypes.constPointerToInt);
+ }
+
// constexpr int waldo1();
// constexpr int (*waldo2())(int);
// struct S { constexpr int waldo3(); };
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticTestBase.java
index 3cd2404c478..aff2182fed0 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticTestBase.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticTestBase.java
@@ -83,6 +83,7 @@ public class SemanticTestBase extends BaseTestCase {
public static IType constChar = constOf(char_);
public static IType constInt = constOf(int_);
public static IType pointerToInt = pointerTo(int_);
+ public static IType constPointerToInt = constPointerTo(int_);
public static IType pointerToConstChar = pointerTo(constChar);
public static IType pointerToConstInt = pointerTo(constInt);
public static IType referenceToInt = referenceTo(int_);
@@ -90,11 +91,18 @@ public class SemanticTestBase extends BaseTestCase {
public static IType rvalueReferenceToInt = rvalueReferenceTo(int_);
public static IType rvalueReferenceToConstInt = rvalueReferenceTo(constInt);
+ // Not quite the same as constOf(pointerTo(type)) because of the
+ // idiosyncratic way we represent cosnt pointers using a flag
+ // on the CPPPointerType rather than using CPPQualifierType.
+ private static IType constPointerTo(IType type) {
+ return new CPPPointerType(type, true, false, false);
+ }
+
private static IType pointerTo(IType type) {
return new CPPPointerType(type);
}
- private static IType constOf(IType type) {
+ public static IType constOf(IType type) {
return new CPPQualifierType(type, true, false);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
index d39a95274a1..7e3f47306c7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
@@ -2140,9 +2140,11 @@ public class CPPVisitor extends ASTQueries {
}
IType type = createType(declSpec);
- type = makeConstIfConstexpr(type, declSpec, declarator);
type = createType(type, declarator, flags);
+ // constexpr implies toplevel-const
+ type = makeConstIfConstexpr(type, declSpec, declarator);
+
// C++ specification 8.3.4.3 and 8.5.1.4
IASTNode initClause = declarator.getInitializer();
if (initClause instanceof IASTEqualsInitializer) {

Back to the top