2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / ext / is_polymorphic.C
blobded071b1d02aa851e05751471c72c0e9e8dc73b6
1 // { dg-do "run" }
2 #include <cassert>
3 #include <exception>
5 struct A
7   double a;
8   double b;
9 };
11 class B
13   virtual void rotate(int) { }
16 class C
17 : public B { };
19 union U
21   double a;
22   double b;
25 template<typename T>
26   bool
27   f()
28   { return __is_polymorphic(T); } 
30 template<typename T>
31   class My
32   {
33   public:
34     bool
35     f()
36     { return !!__is_polymorphic(T); }
37   };
39 template<typename T>
40   class My2
41   {
42   public:
43     static const bool trait = __is_polymorphic(T);
44   };
46 template<typename T>
47   const bool My2<T>::trait;
49 template<typename T, bool b = __is_polymorphic(T)>
50   struct My3_help
51   { static const bool trait = b; };
53 template<typename T, bool b>
54   const bool My3_help<T, b>::trait;
56 template<typename T>
57   class My3
58   {
59   public:
60     bool
61     f()
62     { return My3_help<T>::trait; }
63   };
65 #define PTEST(T) (__is_polymorphic(T) && f<T>() \
66                   && My<T>().f() && My2<T>::trait && My3<T>().f())
68 #define NTEST(T) (!__is_polymorphic(T) && !f<T>() \
69                   && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
71 int main()
73   assert (NTEST (int));
74   assert (NTEST (void));
75   assert (PTEST (std::exception));
76   assert (NTEST (A));
77   assert (PTEST (B));
78   assert (PTEST (C));
79   assert (NTEST (C[]));
80   assert (NTEST (U));
82   return 0;