* doc/extend.texi (Loop-Specific Pragmas): Document pragma GCC unroll.
[official-gcc.git] / gcc / testsuite / g++.dg / ext / has_nothrow_copy-1.C
blob04f681f602a1f73b86ec3072e572b9a1d23d3990
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 #if __cplusplus > 201402L
19 #define THROW_INT
20 #else
21 #define THROW_INT throw(int)    // { dg-warning "deprecated" "" { target { c++11 && { ! c++17 } } } }
22 #endif
24 struct D
26   D(const D&) throw() { }
29 struct E
31   E(const E&) THROW_INT { }
34 struct E1
36   E1(const E1&) THROW_INT { throw int(); }
39 struct F
41   F() throw() { }
44 struct G
46   G() THROW_INT { throw int(); }
49 struct H
51   H(H&) THROW_INT { }
54 struct H1
56   H1(H1&) THROW_INT { throw int(); }
59 struct I
61   I(I&) THROW_INT { }
62   I(const I&) throw() { }
65 struct I1
67   I1(I1&) THROW_INT { throw int(); }
68   I1(const I1&) throw() { }
71 struct J
73   J(J&) throw() { }
74   J(const J&) throw() { }
75   J(volatile J&) throw() { }
76   J(const volatile J&) throw() { }
79 template<typename T>
80   bool
81   f()
82   { return __has_nothrow_copy(T); } 
84 template<typename T>
85   class My
86   {
87   public:
88     bool
89     f()
90     { return !!__has_nothrow_copy(T); }
91   };
93 template<typename T>
94   class My2
95   {
96   public:
97     static const bool trait = __has_nothrow_copy(T);
98   };
100 template<typename T>
101   const bool My2<T>::trait;
103 template<typename T, bool b = __has_nothrow_copy(T)>
104   struct My3_help
105   { static const bool trait = b; };
107 template<typename T, bool b>
108   const bool My3_help<T, b>::trait;
110 template<typename T>
111   class My3
112   {
113   public:
114     bool
115     f()
116     { return My3_help<T>::trait; }
117   };
119 #define PTEST(T) (__has_nothrow_copy(T) && f<T>() \
120                   && My<T>().f() && My2<T>::trait && My3<T>().f())
122 #define NTEST(T) (!__has_nothrow_copy(T) && !f<T>() \
123                   && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
125 int main()
127   assert (PTEST (int));
128   assert (NTEST (int (int)));
129   assert (NTEST (void));
130   assert (PTEST (A));
131   assert (PTEST (B));
132   assert (PTEST (C));
133   assert (PTEST (C[]));
134   assert (PTEST (D));
135   assert (NTEST (E));
136   assert (NTEST (E1));
137   assert (PTEST (F));
138   assert (PTEST (G));
139   assert (NTEST (H));
140   assert (NTEST (H1));
141   assert (NTEST (I));
142   assert (NTEST (I1));  
143   assert (PTEST (J));
145   return 0;