Skip to content

Commit cfde8a5

Browse files
committed
Add VLA tests
1 parent fdf7aa1 commit cfde8a5

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5600,6 +5600,9 @@ bool Sema::IsCXXTriviallyRelocatableType(QualType Type) {
56005600

56015601
QualType BaseElementType = getASTContext().getBaseElementType(Type);
56025602

5603+
if(Type->isVariableArrayType())
5604+
return false;
5605+
56035606
if (BaseElementType.hasNonTrivialObjCLifetime())
56045607
return false;
56055608

@@ -5628,6 +5631,10 @@ static bool IsCXXReplaceableType(Sema &S, const CXXRecordDecl *RD) {
56285631
bool Sema::IsCXXReplaceableType(QualType Type) {
56295632
if (Type.isConstQualified() || Type.isVolatileQualified())
56305633
return false;
5634+
5635+
if(Type->isVariableArrayType())
5636+
return false;
5637+
56315638
QualType BaseElementType =
56325639
getASTContext().getBaseElementType(Type.getUnqualifiedType());
56335640
if (BaseElementType->isIncompleteType())

clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@ static_assert(!__builtin_is_replaceable(WithVBase<S<const int>>));
279279
static_assert(!__builtin_is_replaceable(WithVBase<UserProvidedMove>));
280280
static_assert(__builtin_is_replaceable(WithVirtual));
281281

282+
int n = 4; // expected-note 2{{declared here}}
283+
static_assert(!__builtin_is_cpp_trivially_relocatable(int[n]));
284+
// expected-warning@-1 {{variable length arrays in C++ are a Clang extension}}
285+
// expected-note@-2 {{read of non-const variable 'n' is not allowed in a constant expression}}
286+
static_assert(!__builtin_is_replaceable(int[n]));
287+
// expected-warning@-1 {{variable length arrays in C++ are a Clang extension}}
288+
// expected-note@-2 {{read of non-const variable 'n' is not allowed in a constant expression}}
289+
282290

283291
struct U1 replaceable_if_eligible {
284292
~U1() = delete;

0 commit comments

Comments
 (0)