OSDN Git Service

2012-06-14 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / ext / has_trivial_copy.C
1 // { dg-do run }
2 #include <cassert>
3
4 struct A
5 {
6   double a;
7   double b;
8 };
9
10 union U
11 {
12   double a;
13   double b;
14 };
15
16 struct B
17 {
18   B(const B&) { }
19 };
20
21 struct C
22 {
23   virtual int f() { return 1; }
24 };
25
26 struct D 
27 : public B { };
28
29 struct E
30 : public A { };
31
32 struct F
33 {
34   A a;
35 };
36
37 struct G
38 {
39   B b;
40 };
41
42 template<typename T>
43   bool
44   f()
45   { return __has_trivial_copy(T); } 
46
47 template<typename T>
48   class My
49   {
50   public:
51     bool
52     f()
53     { return !!__has_trivial_copy(T); }
54   };
55
56 template<typename T>
57   class My2
58   {
59   public:
60     static const bool trait = __has_trivial_copy(T);
61   };
62
63 template<typename T>
64   const bool My2<T>::trait;
65
66 template<typename T, bool b = __has_trivial_copy(T)>
67   struct My3_help
68   { static const bool trait = b; };
69
70 template<typename T, bool b>
71   const bool My3_help<T, b>::trait;
72
73 template<typename T>
74   class My3
75   {
76   public:
77     bool
78     f()
79     { return My3_help<T>::trait; }
80   };
81
82 #define PTEST(T) (__has_trivial_copy(T) && f<T>() \
83                   && My<T>().f() && My2<T>::trait && My3<T>().f())
84
85 #define NTEST(T) (!__has_trivial_copy(T) && !f<T>() \
86                   && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
87
88 int main()
89 {
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&));
103
104   return 0;
105 }