diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-05-24 14:17:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-24 14:17:26 +0200 |
commit | 294643e4bdc843343ef20069a4d6d0de872b3303 (patch) | |
tree | d539a58519fc10b8f7e63f3293c827dcedb6e3ec /clang/test/AST/ByteCode | |
parent | 7cfdd74f0f25c0792047f3934c9e93ce1d4788e1 (diff) | |
download | llvm-294643e4bdc843343ef20069a4d6d0de872b3303.zip llvm-294643e4bdc843343ef20069a4d6d0de872b3303.tar.gz llvm-294643e4bdc843343ef20069a4d6d0de872b3303.tar.bz2 |
[clang][bytecode] Check lifetime of all ptr bases in placement-new (#141272)
placement-new'ing an object with a dead base object is not allowed, so
we need to check all the pointer bases.
Diffstat (limited to 'clang/test/AST/ByteCode')
-rw-r--r-- | clang/test/AST/ByteCode/new-delete.cpp | 7 | ||||
-rw-r--r-- | clang/test/AST/ByteCode/placement-new.cpp | 16 |
2 files changed, 18 insertions, 5 deletions
diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp index 6726659..1ee41a9 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -682,17 +682,16 @@ namespace OperatorNewDelete { } static_assert(zeroAlloc()); - /// FIXME: This is broken in the current interpreter. constexpr int arrayAlloc() { int *F = std::allocator<int>().allocate(2); - F[0] = 10; // ref-note {{assignment to object outside its lifetime is not allowed in a constant expression}} + F[0] = 10; // both-note {{assignment to object outside its lifetime is not allowed in a constant expression}} F[1] = 13; int Res = F[1] + F[0]; std::allocator<int>().deallocate(F); return Res; } - static_assert(arrayAlloc() == 23); // ref-error {{not an integral constant expression}} \ - // ref-note {{in call to}} + static_assert(arrayAlloc() == 23); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} struct S { int i; diff --git a/clang/test/AST/ByteCode/placement-new.cpp b/clang/test/AST/ByteCode/placement-new.cpp index 81f7782..a301c96 100644 --- a/clang/test/AST/ByteCode/placement-new.cpp +++ b/clang/test/AST/ByteCode/placement-new.cpp @@ -17,13 +17,16 @@ namespace std { // both-note {{placement new would change type of storage from 'int' to 'float'}} \ // both-note {{construction of subobject of member 'x' of union with active member 'a' is not allowed in a constant expression}} \ // both-note {{construction of temporary is not allowed}} \ - // both-note {{construction of heap allocated object that has been deleted}} + // both-note {{construction of heap allocated object that has been deleted}} \ + // both-note {{construction of subobject of object outside its lifetime is not allowed in a constant expression}} } } void *operator new(std::size_t, void *p) { return p; } void* operator new[] (std::size_t, void* p) {return p;} +constexpr int no_lifetime_start = (*std::allocator<int>().allocate(1) = 1); // both-error {{constant expression}} \ + // both-note {{assignment to object outside its lifetime}} consteval auto ok1() { bool b; @@ -409,3 +412,14 @@ namespace PlacementNewAfterDelete { static_assert(construct_after_lifetime()); // both-error {{}} \ // both-note {{in call}} } + +namespace SubObj { + constexpr bool construct_after_lifetime_2() { + struct A { struct B {} b; }; + A a; + a.~A(); + std::construct_at<A::B>(&a.b); // both-note {{in call}} + return true; + } + static_assert(construct_after_lifetime_2()); // both-error {{}} both-note {{in call}} +} |