aboutsummaryrefslogtreecommitdiff
path: root/clang/test/AST/ByteCode/cxx2a.cpp
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2025-01-09 17:50:40 +0900
committerNAKAMURA Takumi <geek4civic@gmail.com>2025-01-09 17:50:40 +0900
commitfea7da1b00cc97d742faede2df96c7d327950f49 (patch)
tree4de1d6b4ddc69f4f32daabb11ad5c71ab0cf895e /clang/test/AST/ByteCode/cxx2a.cpp
parent9b99dde0d47102625d93c5d1cbbc04951025a6c9 (diff)
parent0aa930a41f2d1ebf1fa90ec42da8f96d15a4dcbb (diff)
downloadllvm-users/chapuni/cov/single/nextcount.zip
llvm-users/chapuni/cov/single/nextcount.tar.gz
llvm-users/chapuni/cov/single/nextcount.tar.bz2
Merge branch 'users/chapuni/cov/single/nextcount-base' into users/chapuni/cov/single/nextcountusers/chapuni/cov/single/nextcount
Diffstat (limited to 'clang/test/AST/ByteCode/cxx2a.cpp')
-rw-r--r--clang/test/AST/ByteCode/cxx2a.cpp60
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());
+}