2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / ext / has_trivial_copy.C
blob4b8cc1541477c7966c5c4e4cea5bb8ec96ee5cb4
1 // { dg-do "run" }
2 #include <cassert>
4 struct A
6   double a;
7   double b;
8 };
10 union U
12   double a;
13   double b;
16 struct B
18   B(const B&) { }
21 struct C
23   virtual int f() { return 1; }
26 struct D 
27 : public B { };
29 struct E
30 : public A { };
32 struct F
34   A a;
37 struct G
39   B b;
42 template<typename T>
43   bool
44   f()
45   { return __has_trivial_copy(T); } 
47 template<typename T>
48   class My
49   {
50   public:
51     bool
52     f()
53     { return !!__has_trivial_copy(T); }
54   };
56 template<typename T>
57   class My2
58   {
59   public:
60     static const bool trait = __has_trivial_copy(T);
61   };
63 template<typename T>
64   const bool My2<T>::trait;
66 template<typename T, bool b = __has_trivial_copy(T)>
67   struct My3_help
68   { static const bool trait = b; };
70 template<typename T, bool b>
71   const bool My3_help<T, b>::trait;
73 template<typename T>
74   class My3
75   {
76   public:
77     bool
78     f()
79     { return My3_help<T>::trait; }
80   };
82 #define PTEST(T) (__has_trivial_copy(T) && f<T>() \
83                   && My<T>().f() && My2<T>::trait && My3<T>().f())
85 #define NTEST(T) (!__has_trivial_copy(T) && !f<T>() \
86                   && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
88 int main()
90   assert (PTEST (int));
91   assert (NTEST (int (int)));
92   assert (NTEST (void));
93   assert (PTEST (A));
94   assert (PTEST (U));
95   assert (NTEST (B));
96   assert (NTEST (C));
97   assert (NTEST (D));
98   assert (PTEST (E));
99   assert (PTEST (E[]));
100   assert (PTEST (F));
101   assert (NTEST (G));
102   assert (PTEST (B&));
104   return 0;