Debian Codegraph @

gcc/testsuite/g++.dg/ext/has_nothrow_copy-1.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } }
3 #include <cassert>
4
5 struct A
6 {
7 double a;
8 double b;
9 };
10
11 struct B
12 {
13 A a;
14 };
15
16 struct C
17 : public A { };
18
19 #if __cplusplus > 201402L
20 #define THROW_INT
21 #else
22 #define THROW_INT throw(int) // { dg-warning "deprecated" "" { target { c++11 && { ! c++17 } } } }
23 #endif
24
25 struct D
26 {
27 D(const D&) throw() { }
28 };
29
30 struct E
31 {
32 E(const E&) THROW_INT { }
33 };
34
35 struct E1
36 {
37 E1(const E1&) THROW_INT { throw int(); }
38 };
39
40 struct F
41 {
42 F() throw() { }
43 };
44
45 struct G
46 {
47 G() THROW_INT { throw int(); }
48 };
49
50 struct H
51 {
52 H(H&) THROW_INT { }
53 };
54
55 struct H1
56 {
57 H1(H1&) THROW_INT { throw int(); }
58 };
59
60 struct I
61 {
62 I(I&) THROW_INT { }
63 I(const I&) throw() { }
64 };
65
66 struct I1
67 {
68 I1(I1&) THROW_INT { throw int(); }
69 I1(const I1&) throw() { }
70 };
71
72 struct J
73 {
74 J(J&) throw() { }
75 J(const J&) throw() { }
76 J(volatile J&) throw() { }
77 J(const volatile J&) throw() { }
78 };
79
80 template<typename T>
81 bool
82 f()
83 { return __has_nothrow_copy(T); }
84
85 template<typename T>
86 class My
87 {
88 public:
89 bool
90 f()
91 { return !!__has_nothrow_copy(T); }
92 };
93
94 template<typename T>
95 class My2
96 {
97 public:
98 static const bool trait = __has_nothrow_copy(T);
99 };
100
101 template<typename T>
102 const bool My2<T>::trait;
103
104 template<typename T, bool b = __has_nothrow_copy(T)>
105 struct My3_help
106 { static const bool trait = b; };
107
108 template<typename T, bool b>
109 const bool My3_help<T, b>::trait;
110
111 template<typename T>
112 class My3
113 {
114 public:
115 bool
116 f()
117 { return My3_help<T>::trait; }
118 };
119
120 #define PTEST(T) (__has_nothrow_copy(T) && f<T>() \
121 && My<T>().f() && My2<T>::trait && My3<T>().f())
122
123 #define NTEST(T) (!__has_nothrow_copy(T) && !f<T>() \
124 && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
125
126 int main()
127 {
128 assert (PTEST (int));
129 assert (NTEST (int (int)));
130 assert (NTEST (void));
131 assert (PTEST (A));
132 assert (PTEST (B));
133 assert (PTEST (C));
134 assert (PTEST (C[]));
135 assert (PTEST (D));
136 assert (NTEST (E));
137 assert (NTEST (E1));
138 assert (PTEST (F));
139 assert (PTEST (G));
140 assert (NTEST (H));
141 assert (NTEST (H1));
142 assert (NTEST (I));
143 assert (NTEST (I1));
144 assert (PTEST (J));
145
146 return 0;
147 }