145
|
1 // PR c++/88337 - Implement P1327R1: Allow dynamic_cast/typeid in constexpr.
|
|
2 // { dg-do compile { target c++2a } }
|
|
3 // Test typeid in a template.
|
|
4
|
|
5 #include <typeinfo>
|
|
6
|
|
7 struct B { virtual void fn (); };
|
|
8 struct D : B { };
|
|
9
|
|
10 void abort ();
|
|
11
|
|
12 template<typename>
|
|
13 constexpr void
|
|
14 fn ()
|
|
15 {
|
|
16 D d;
|
|
17 if (&typeid (d) != &typeid (D))
|
|
18 abort ();
|
|
19 }
|
|
20 constexpr bool b1 = (fn<int>(), true);
|
|
21
|
|
22 // Type-dependent.
|
|
23 template<typename T>
|
|
24 constexpr void
|
|
25 fn2 ()
|
|
26 {
|
|
27 T t{};
|
|
28 if (&typeid (t) != &typeid (T))
|
|
29 abort ();
|
|
30 }
|
|
31 constexpr bool b2 = (fn2<int>(), true);
|
|
32 constexpr bool b3 = (fn2<B>(), true);
|
|
33 constexpr bool b4 = (fn2<D>(), true);
|