OSDN Git Service

* g++.dg/ext/attrib35.C: Fix target selector string.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / ext / has_trivial_constructor.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() { }
19 };
20
21 struct C 
22 : public B { };
23
24 struct D
25 : public A { };
26
27 struct E
28 {
29   A a;
30 };
31
32 struct F
33 {
34   B b;
35 };
36
37 template<typename T>
38   bool
39   f()
40   { return __has_trivial_constructor(T); } 
41
42 template<typename T>
43   class My
44   {
45   public:
46     bool
47     f()
48     { return !!__has_trivial_constructor(T); }
49   };
50
51 template<typename T>
52   class My2
53   {
54   public:
55     static const bool trait = __has_trivial_constructor(T);
56   };
57
58 template<typename T>
59   const bool My2<T>::trait;
60
61 template<typename T, bool b = __has_trivial_constructor(T)>
62   struct My3_help
63   { static const bool trait = b; };
64
65 template<typename T, bool b>
66   const bool My3_help<T, b>::trait;
67
68 template<typename T>
69   class My3
70   {
71   public:
72     bool
73     f()
74     { return My3_help<T>::trait; }
75   };
76
77 #define PTEST(T) (__has_trivial_constructor(T) && f<T>() \
78                   && My<T>().f() && My2<T>::trait && My3<T>().f())
79
80 #define NTEST(T) (!__has_trivial_constructor(T) && !f<T>() \
81                   && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
82
83 int main()
84 {
85   assert (PTEST (int));
86   assert (NTEST (int (int)));
87   assert (NTEST (void));
88   assert (PTEST (A));
89   assert (PTEST (U));
90   assert (NTEST (B));
91   assert (NTEST (C));
92   assert (PTEST (D));
93   assert (PTEST (D[]));
94   assert (PTEST (E));
95   assert (NTEST (F));
96
97   return 0;
98 }