aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/rtti/typeid10.C
blob: 47b45b1056dd68d81c4d40b5ddb2bfa6d81a8c55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// PR c++/25466
// { dg-do run }

#include <typeinfo>

const std::type_info *a;

template <class T>
bool is_polymorphic() {
   bool result(false);
   const std::type_info &a1 = typeid( (result=true), *(T*)0);
   a = &a1;
   return result;
}

struct non_polymorphic {};
struct polymorphic { virtual ~polymorphic() {} };


int main() {
  if (is_polymorphic<int>()) __builtin_abort();
  if (is_polymorphic<non_polymorphic>()) __builtin_abort();
  try
    {
      is_polymorphic<polymorphic>();
      __builtin_abort(); // should have thrown bad_typeid
    }
  catch (std::bad_typeid&)
    {
      // OK
    }
  catch (...)
    {
      __builtin_abort();
    }
}