Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5613,8 +5613,13 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
// A constexpr specifier used in an object declaration declares the object
// as const.
if (D.getDeclSpec().getConstexprSpecifier() == ConstexprSpecKind::Constexpr &&
T->isObjectType())
T->isObjectType()) {
T.addConst();
// C++ 9.3.3.4p3: Any type of the form "cv-qualifier-seq array of N U" is
// adjusted to "array of N cv-qualifier-seq U".
if (const ArrayType *AType = Context.getAsArrayType(T))
T = QualType(AType, 0);
}

// C++2a [dcl.fct]p4:
// A parameter with volatile-qualified type is deprecated
Expand Down
2 changes: 1 addition & 1 deletion clang/test/AST/ByteCode/constexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ constexpr TheA V19[3] = {};
constexpr TheV V20[3] = {};
// both-error@-1 {{constexpr variable cannot have type 'const TheV[3]' (aka 'const volatile short[3]')}}
constexpr TheR V21[3] = {};
// both-error@-1 {{constexpr variable cannot have type 'const TheR[3]' (aka 'float *restrict const[3]')}}
// both-error@-1 {{constexpr variable cannot have type 'const TheR[3]' (aka 'float *const restrict[3]')}}

struct HasA {
TheA f;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Sema/constexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ constexpr TheA V19[3] = {};
constexpr TheV V20[3] = {};
// expected-error@-1 {{constexpr variable cannot have type 'const TheV[3]' (aka 'const volatile short[3]')}}
constexpr TheR V21[3] = {};
// expected-error@-1 {{constexpr variable cannot have type 'const TheR[3]' (aka 'float *restrict const[3]')}}
// expected-error@-1 {{constexpr variable cannot have type 'const TheR[3]' (aka 'float *const restrict[3]')}}

struct HasA {
TheA f;
Expand Down
8 changes: 8 additions & 0 deletions clang/test/SemaCXX/constexpr-implicit-const-97005.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %clang_cc1 -triple x86_64-linux-gnu -ast-dump %s | FileCheck %s

bool aaa;
constexpr const unsigned char ccc[] = { 5 };
constexpr const unsigned char ddd[1] = { 0 };
auto bbb = (aaa ? ddd : ccc);

// CHECK: DeclRefExpr {{.*}} 'const unsigned char[1]' {{.*}} 'ddd' 'const unsigned char[1]'