1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 541670 - constexpr implies toplevel const

Change-Id: I318a9293d12eeecb7f49bfba1acb849109fab666
This commit is contained in:
Nathan Ridge 2018-11-28 22:41:32 -05:00
parent 9e44f3634a
commit 586ccf790b
3 changed files with 17 additions and 2 deletions

View file

@ -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(); };

View file

@ -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);
}

View file

@ -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) {