diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-03-17 19:01:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-17 19:01:35 +0100 |
commit | ca1bde0b91a6129e7bacee0fa67e4331b06dd683 (patch) | |
tree | ddb00f2ef0c023d8863a83a652a73627af114579 /clang/test/AST/ByteCode | |
parent | c53caae1d0baaf21d63e5f7152171699bcab0750 (diff) | |
download | llvm-ca1bde0b91a6129e7bacee0fa67e4331b06dd683.zip llvm-ca1bde0b91a6129e7bacee0fa67e4331b06dd683.tar.gz llvm-ca1bde0b91a6129e7bacee0fa67e4331b06dd683.tar.bz2 |
[clang][bytecode] Check dtor instance pointers for active-ness (#128732)
And diagnose if we're trying to destroy an inactive member of a union.
Diffstat (limited to 'clang/test/AST/ByteCode')
-rw-r--r-- | clang/test/AST/ByteCode/unions.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/unions.cpp b/clang/test/AST/ByteCode/unions.cpp index 72b9b18..70524fd 100644 --- a/clang/test/AST/ByteCode/unions.cpp +++ b/clang/test/AST/ByteCode/unions.cpp @@ -522,4 +522,52 @@ namespace MemberCalls { static_assert(foo()); // both-error {{not an integral constant expression}} \ // both-note {{in call to}} } + +namespace InactiveDestroy { + struct A { + constexpr ~A() {} + }; + union U { + A a; + constexpr ~U() { + } + }; + + constexpr bool foo() { // both-error {{never produces a constant expression}} + U u; + u.a.~A(); // both-note 2{{destruction of member 'a' of union with no active member}} + return true; + } + static_assert(foo()); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} +} + +namespace InactiveTrivialDestroy { + struct A {}; + union U { + A a; + }; + + constexpr bool foo() { // both-error {{never produces a constant expression}} + U u; + u.a.~A(); // both-note 2{{destruction of member 'a' of union with no active member}} + return true; + } + static_assert(foo()); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} +} + +namespace ActiveDestroy { + struct A {}; + union U { + A a; + }; + constexpr bool foo2() { + U u{}; + u.a.~A(); + return true; + } + static_assert(foo2()); +} + #endif |