Skip to content

Commit 102c152

Browse files
committed
Add VLA tests
1 parent ff7273a commit 102c152

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
@@ -5273,6 +5273,9 @@ bool Sema::IsCXXTriviallyRelocatableType(QualType Type) {
52735273

52745274
QualType BaseElementType = getASTContext().getBaseElementType(Type);
52755275

5276+
if(Type->isVariableArrayType())
5277+
return false;
5278+
52765279
if (BaseElementType.hasNonTrivialObjCLifetime())
52775280
return false;
52785281

@@ -5301,6 +5304,10 @@ static bool IsCXXReplaceableType(Sema &S, const CXXRecordDecl *RD) {
53015304
bool Sema::IsCXXReplaceableType(QualType Type) {
53025305
if (Type.isConstQualified() || Type.isVolatileQualified())
53035306
return false;
5307+
5308+
if(Type->isVariableArrayType())
5309+
return false;
5310+
53045311
QualType BaseElementType =
53055312
getASTContext().getBaseElementType(Type.getUnqualifiedType());
53065313
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)