diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2025-01-09 18:43:11 +0900 |
---|---|---|
committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2025-01-09 18:43:11 +0900 |
commit | 0e1a753549b29ff1f5a190aca83b803a33b51628 (patch) | |
tree | e5578f8810c65711304128d0c8add7fa1f77b9d8 /clang/test/AST/ByteCode/cxx2a.cpp | |
parent | 3c6252260ee11e3a453076b4d96ffffe20d49998 (diff) | |
parent | bdcf47e4bcb92889665825654bb80a8bbe30379e (diff) | |
download | llvm-users/chapuni/cov/single/if.zip llvm-users/chapuni/cov/single/if.tar.gz llvm-users/chapuni/cov/single/if.tar.bz2 |
Merge branch 'users/chapuni/cov/single/base' into users/chapuni/cov/single/ifusers/chapuni/cov/single/if
Conflicts:
clang/lib/CodeGen/CoverageMappingGen.cpp
Diffstat (limited to 'clang/test/AST/ByteCode/cxx2a.cpp')
-rw-r--r-- | clang/test/AST/ByteCode/cxx2a.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/cxx2a.cpp b/clang/test/AST/ByteCode/cxx2a.cpp index eaae978..f600688 100644 --- a/clang/test/AST/ByteCode/cxx2a.cpp +++ b/clang/test/AST/ByteCode/cxx2a.cpp @@ -110,3 +110,63 @@ namespace DtorOrder { } static_assert(check_abnormal_termination()); } + +namespace std { + struct type_info; +} + +namespace TypeId { + struct A { + const std::type_info &ti = typeid(*this); + }; + struct A2 : A {}; + static_assert(&A().ti == &typeid(A)); + static_assert(&typeid((A2())) == &typeid(A2)); + extern A2 extern_a2; + static_assert(&typeid(extern_a2) == &typeid(A2)); + + constexpr A2 a2; + constexpr const A &a1 = a2; + static_assert(&typeid(a1) == &typeid(A)); + + struct B { + virtual void f(); + const std::type_info &ti1 = typeid(*this); + }; + struct B2 : B { + const std::type_info &ti2 = typeid(*this); + }; + static_assert(&B2().ti1 == &typeid(B)); + static_assert(&B2().ti2 == &typeid(B2)); + extern B2 extern_b2; + static_assert(&typeid(extern_b2) == &typeid(B2)); // both-error {{constant expression}} \ + // both-note{{typeid applied to object 'extern_b2' whose dynamic type is not constant}} + + + constexpr B2 b2; + constexpr const B &b1 = b2; + static_assert(&typeid(b1) == &typeid(B2)); + + constexpr bool side_effects() { + // Not polymorphic nor a glvalue. + bool OK = true; + (void)typeid(OK = false, A2()); // both-warning {{has no effect}} + if (!OK) return false; + + // Not polymorphic. + A2 a2; + (void)typeid(OK = false, a2); // both-warning {{has no effect}} + if (!OK) return false; + + // Not a glvalue. + (void)typeid(OK = false, B2()); // both-warning {{has no effect}} + if (!OK) return false; + + // Polymorphic glvalue: operand evaluated. + OK = false; + B2 b2; + (void)typeid(OK = true, b2); // both-warning {{will be evaluated}} + return OK; + } + static_assert(side_effects()); +} |