Debian Codegraph @

gcc/testsuite/g++.dg/rtti/typeid10.C

raw
1 // PR c++/25466
2 // { dg-do run }
3
4 #include <typeinfo>
5
6 const std::type_info *a;
7
8 template <class T>
9 bool is_polymorphic() {
10 bool result(false);
11 const std::type_info &a1 = typeid( (result=true), *(T*)0);
12 a = &a1;
13 return result;
14 }
15
16 struct non_polymorphic {};
17 struct polymorphic { virtual ~polymorphic() {} };
18
19
20 int main() {
21 if (is_polymorphic<int>()) __builtin_abort();
22 if (is_polymorphic<non_polymorphic>()) __builtin_abort();
23 try
24 {
25 is_polymorphic<polymorphic>();
26 __builtin_abort(); // should have thrown bad_typeid
27 }
28 catch (std::bad_typeid&)
29 {
30 // OK
31 }
32 catch (...)
33 {
34 __builtin_abort();
35 }
36 }