]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/g++.dg/ext/has_nothrow_constructor.C
invoke.texi: Document -std=c++17 and -std=gnu++17 and document c++1z and gnu++1z...
[thirdparty/gcc.git] / gcc / testsuite / g++.dg / ext / has_nothrow_constructor.C
1 // { dg-do run }
2 #include <cassert>
3
4 struct A
5 {
6 double a;
7 double b;
8 };
9
10 struct B
11 {
12 A a;
13 };
14
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
20
21 struct C
22 : public A { };
23
24 struct D
25 {
26 D() throw() { }
27 };
28
29 struct E
30 {
31 E() THROW_INT { }
32 };
33
34 struct E1
35 {
36 E1() THROW_INT { throw int(); }
37 };
38
39 struct F
40 {
41 F(const F&) throw() { }
42 };
43
44 struct G
45 {
46 G(const G&) THROW_INT { throw int(); }
47 };
48
49 template<typename T>
50 bool
51 f()
52 { return __has_nothrow_constructor(T); }
53
54 template<typename T>
55 class My
56 {
57 public:
58 bool
59 f()
60 { return !!__has_nothrow_constructor(T); }
61 };
62
63 template<typename T>
64 class My2
65 {
66 public:
67 static const bool trait = __has_nothrow_constructor(T);
68 };
69
70 template<typename T>
71 const bool My2<T>::trait;
72
73
74 template<typename T, bool b = __has_nothrow_constructor(T)>
75 struct My3_help
76 { static const bool trait = b; };
77
78 template<typename T, bool b>
79 const bool My3_help<T, b>::trait;
80
81 template<typename T>
82 class My3
83 {
84 public:
85 bool
86 f()
87 { return My3_help<T>::trait; }
88 };
89
90 #define PTEST(T) (__has_nothrow_constructor(T) && f<T>() \
91 && My<T>().f() && My2<T>::trait && My3<T>().f())
92
93 #define NTEST(T) (!__has_nothrow_constructor(T) && !f<T>() \
94 && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
95
96 int main()
97 {
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));
110
111 return 0;
112 }