2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / ext / has_nothrow_assign.C
blobf3b4a8b2556dec36620d3035cfe9a7f4f4b2fd0c
1 // { dg-do "run" }
2 #include <cassert>
4 struct A
6   double a;
7   double b;
8 };
10 struct B
12   A a;
15 struct C
16 : public A { };
18 struct D
20   D& operator=(const D&) throw() { return *this; }
23 struct E
25   E& operator=(const E&) throw(int) { return *this; }
28 struct E1
30   E1& operator=(const E1&) throw(int) { throw int(); return *this; }
33 struct F
35   F() throw(int) { }
38 struct G
40   G() throw(int) { throw int(); }
43 struct H
45   H& operator=(H&) throw(int) { return *this; }
48 struct H1
50   H1& operator=(H1&) throw(int) { throw int(); return *this; }
53 struct I
55   I& operator=(I&) throw(int) { return *this; }
56   I& operator=(const I&) throw() { return *this; }
59 struct I1
61   I1& operator=(I1&) throw(int) { throw int(); return *this; }
62   I1& operator=(const I1&) throw() { return *this; }
65 struct J
67   J& operator=(J&) throw() { return *this; }
68   J& operator=(const J&) throw() { return *this; }
69   J& operator=(volatile J&) throw() { return *this; }
70   J& operator=(const volatile J&) throw() { return *this; }
73 struct K
75   K& operator=(K&) throw() { return *this; }
78 struct L
80   L& operator=(const L&) throw() { return *this; }
83 template<typename T>
84   bool
85   f()
86   { return __has_nothrow_assign(T); } 
88 template<typename T>
89   class My
90   {
91   public:
92     bool
93     f()
94     { return !!__has_nothrow_assign(T); }
95   };
97 template<typename T>
98   class My2
99   {
100   public:
101     static const bool trait = __has_nothrow_assign(T);
102   };
104 template<typename T>
105   const bool My2<T>::trait;
107 template<typename T, bool b = __has_nothrow_assign(T)>
108   struct My3_help
109   { static const bool trait = b; };
111 template<typename T, bool b>
112   const bool My3_help<T, b>::trait;
114 template<typename T>
115   class My3
116   {
117   public:
118     bool
119     f()
120     { return My3_help<T>::trait; }
121   };
123 #define PTEST(T) (__has_nothrow_assign(T) && f<T>() \
124                   && My<T>().f() && My2<T>::trait && My3<T>().f())
126 #define NTEST(T) (!__has_nothrow_assign(T) && !f<T>() \
127                   && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
129 int main()
131   assert (PTEST (int));
132   assert (NTEST (int (int)));
133   assert (NTEST (void));
134   assert (PTEST (A));
135   assert (PTEST (B));
136   assert (PTEST (C));
137   assert (PTEST (C[]));
138   assert (PTEST (D));
139   assert (NTEST (E));
140   assert (NTEST (E1));
141   assert (PTEST (F));
142   assert (PTEST (G));
143   assert (NTEST (H));
144   assert (NTEST (H1));
145   assert (NTEST (I));
146   assert (NTEST (I1));
147   assert (PTEST (J));
148   assert (NTEST (const K));
149   assert (NTEST (const L));
151   return 0;