* doc/extend.texi (Loop-Specific Pragmas): Document pragma GCC unroll.
[official-gcc.git] / gcc / testsuite / g++.dg / ext / has_nothrow_constructor.C
blob03304452f8c2d5904965fe6f1d472c3f09eb0bc3
1 // { dg-do run }
2 #include <cassert>
4 struct A
6   double a;
7   double b;
8 };
10 struct B
12   A a;
15 #if __cplusplus > 201402L
16 #define THROW_INT
17 #else
18 #define THROW_INT throw(int)    // { dg-warning "deprecated" "" { target { c++11 && { ! c++17 } } } }
19 #endif
21 struct C 
22 : public A { };
24 struct D
26   D() throw() { }
29 struct E
31   E() THROW_INT { }
34 struct E1
36   E1() THROW_INT { throw int(); }
39 struct F
41   F(const F&) throw() { }
44 struct G
46   G(const G&) THROW_INT { throw int(); }
49 template<typename T>
50   bool
51   f()
52   { return __has_nothrow_constructor(T); } 
54 template<typename T>
55   class My
56   {
57   public:
58     bool
59     f()
60     { return !!__has_nothrow_constructor(T); }
61   };
63 template<typename T>
64   class My2
65   {
66   public:
67     static const bool trait = __has_nothrow_constructor(T);
68   };
70 template<typename T>
71   const bool My2<T>::trait;
74 template<typename T, bool b = __has_nothrow_constructor(T)>
75   struct My3_help
76   { static const bool trait = b; };
78 template<typename T, bool b>
79   const bool My3_help<T, b>::trait;
81 template<typename T>
82   class My3
83   {
84   public:
85     bool
86     f()
87     { return My3_help<T>::trait; }
88   };
90 #define PTEST(T) (__has_nothrow_constructor(T) && f<T>() \
91                   && My<T>().f() && My2<T>::trait && My3<T>().f())
93 #define NTEST(T) (!__has_nothrow_constructor(T) && !f<T>() \
94                   && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
96 int main()
98   assert (PTEST (int));
99   assert (NTEST (int (int)));
100   assert (NTEST (void));
101   assert (PTEST (A));
102   assert (PTEST (B));
103   assert (PTEST (C));
104   assert (PTEST (C[]));
105   assert (PTEST (D));
106   assert (NTEST (E));
107   assert (NTEST (E1));
108   assert (NTEST (F));
109   assert (NTEST (G));
111   return 0;