Debian Codegraph @

gcc/testsuite/g++.dg/ext/has_nothrow_assign.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& operator=(const D&) throw() { return *this; }
28 };
29
30 struct E
31 {
32 E& operator=(const E&) THROW_INT { return *this; }
33 };
34
35 struct E1
36 {
37 E1& operator=(const E1&) THROW_INT { throw int(); return *this; }
38 };
39
40 struct F
41 {
42 F() THROW_INT { }
43 };
44
45 struct G
46 {
47 G() THROW_INT { throw int(); }
48 };
49
50 struct H
51 {
52 H& operator=(H&) THROW_INT { return *this; }
53 };
54
55 struct H1
56 {
57 H1& operator=(H1&) THROW_INT { throw int(); return *this; }
58 };
59
60 struct I
61 {
62 I& operator=(I&) THROW_INT { return *this; }
63 I& operator=(const I&) throw() { return *this; }
64 };
65
66 struct I1
67 {
68 I1& operator=(I1&) THROW_INT { throw int(); return *this; }
69 I1& operator=(const I1&) throw() { return *this; }
70 };
71
72 struct J
73 {
74 J& operator=(J&) throw() { return *this; }
75 J& operator=(const J&) throw() { return *this; }
76 J& operator=(volatile J&) throw() { return *this; }
77 J& operator=(const volatile J&) throw() { return *this; }
78 };
79
80 struct K
81 {
82 K& operator=(K&) throw() { return *this; }
83 };
84
85 struct L
86 {
87 L& operator=(const L&) throw() { return *this; }
88 };
89
90 template<typename T>
91 bool
92 f()
93 { return __has_nothrow_assign(T); }
94
95 template<typename T>
96 class My
97 {
98 public:
99 bool
100 f()
101 { return !!__has_nothrow_assign(T); }
102 };
103
104 template<typename T>
105 class My2
106 {
107 public:
108 static const bool trait = __has_nothrow_assign(T);
109 };
110
111 template<typename T>
112 const bool My2<T>::trait;
113
114 template<typename T, bool b = __has_nothrow_assign(T)>
115 struct My3_help
116 { static const bool trait = b; };
117
118 template<typename T, bool b>
119 const bool My3_help<T, b>::trait;
120
121 template<typename T>
122 class My3
123 {
124 public:
125 bool
126 f()
127 { return My3_help<T>::trait; }
128 };
129
130 #define PTEST(T) (__has_nothrow_assign(T) && f<T>() \
131 && My<T>().f() && My2<T>::trait && My3<T>().f())
132
133 #define NTEST(T) (!__has_nothrow_assign(T) && !f<T>() \
134 && !My<T>().f() && !My2<T>::trait && !My3<T>().f())
135
136 int main()
137 {
138 assert (PTEST (int));
139 assert (NTEST (int (int)));
140 assert (NTEST (void));
141 assert (PTEST (A));
142 assert (PTEST (B));
143 assert (PTEST (C));
144 assert (PTEST (C[]));
145 assert (PTEST (D));
146 assert (NTEST (E));
147 assert (NTEST (E1));
148 assert (PTEST (F));
149 assert (PTEST (G));
150 assert (NTEST (H));
151 assert (NTEST (H1));
152 assert (NTEST (I));
153 assert (NTEST (I1));
154 assert (PTEST (J));
155 assert (NTEST (const K));
156 assert (NTEST (const L));
157
158 return 0;
159 }