]>
Commit | Line | Data |
---|---|---|
95edead9 JW |
1 | // { dg-additional-options "-Wno-deprecated" { target c++2a } } |
2 | // { dg-do compile { target c++17 } } | |
137422c8 | 3 | |
7adcbafe | 4 | // Copyright (C) 2014-2022 Free Software Foundation, Inc. |
137422c8 VV |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 3, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
c7cbb4da | 17 | // You should have received a copy of the GNU General Public License along |
137422c8 VV |
18 | // with this library; see the file COPYING3. If not see |
19 | // <http://www.gnu.org/licenses/>. | |
20 | ||
21 | #include <type_traits> | |
22 | ||
23 | using namespace std; | |
24 | ||
25 | // These tests are rather simple, the front-end tests already test | |
26 | // variable templates, and the library tests for the underlying | |
27 | // traits are more elaborate. These are just simple sanity tests. | |
28 | ||
29 | static_assert(is_void_v<void> && is_void<void>::value, ""); | |
30 | static_assert(!is_void_v<int> && !is_void<int>::value, ""); | |
31 | ||
32 | static_assert(is_null_pointer_v<nullptr_t> | |
33 | && is_null_pointer<nullptr_t>::value, ""); | |
34 | static_assert(!is_null_pointer_v<void*> | |
35 | && !is_null_pointer<void*>::value, ""); | |
36 | ||
37 | static_assert(is_integral_v<int> && is_integral<int>::value, ""); | |
38 | static_assert(!is_integral_v<int*> && !is_integral<int*>::value, ""); | |
39 | ||
40 | static_assert(is_floating_point_v<float> | |
41 | && is_floating_point<float>::value, ""); | |
42 | static_assert(!is_floating_point_v<int> | |
43 | && !is_floating_point<int>::value, ""); | |
44 | ||
45 | static_assert(is_array_v<char[42]> && is_array<char[42]>::value, ""); | |
46 | static_assert(!is_array_v<char*> && !is_array<char*>::value, ""); | |
47 | ||
48 | static_assert(is_pointer_v<int*> && is_pointer<int*>::value, ""); | |
49 | static_assert(!is_pointer_v<int> && !is_pointer<int>::value, ""); | |
50 | ||
51 | static_assert(is_lvalue_reference_v<int&> | |
52 | && is_lvalue_reference<int&>::value, ""); | |
53 | static_assert(!is_lvalue_reference_v<int> | |
54 | && !is_lvalue_reference<int>::value, ""); | |
55 | ||
56 | static_assert(is_rvalue_reference_v<int&&> | |
57 | && is_rvalue_reference<int&&>::value, ""); | |
58 | static_assert(!is_rvalue_reference_v<int> | |
59 | && !is_rvalue_reference<int>::value, ""); | |
60 | ||
61 | struct EmptyFinal final {}; | |
62 | ||
63 | static_assert(is_member_object_pointer_v<int (EmptyFinal::*)> | |
64 | && is_member_object_pointer<int (EmptyFinal::*)>::value, ""); | |
65 | static_assert(!is_member_object_pointer_v<void*> | |
66 | && !is_member_object_pointer<void*>::value, ""); | |
67 | ||
68 | static_assert(is_member_function_pointer_v<int (EmptyFinal::*)()> | |
69 | && is_member_function_pointer<int (EmptyFinal::*)()>::value, ""); | |
70 | static_assert(!is_member_function_pointer_v<void*> | |
71 | && !is_member_function_pointer<void*>::value, ""); | |
72 | ||
73 | enum Enum {}; | |
74 | ||
75 | static_assert(is_enum_v<Enum> && is_enum<Enum>::value, ""); | |
76 | static_assert(!is_enum_v<int> && !is_enum<int>::value, ""); | |
77 | ||
78 | union Union; | |
79 | ||
80 | static_assert(is_union_v<Union> && is_union<Union>::value, ""); | |
81 | static_assert(!is_union_v<int> && !is_union<int>::value, ""); | |
82 | ||
83 | static_assert(is_class_v<EmptyFinal> && is_class<EmptyFinal>::value, ""); | |
84 | static_assert(!is_class_v<int> && !is_class<int>::value, ""); | |
85 | ||
86 | static_assert(is_function_v<void()> && is_function<void()>::value, ""); | |
87 | static_assert(!is_function_v<void(*)()> && !is_function<void(*)()>::value, ""); | |
88 | ||
89 | static_assert(is_reference_v<int&> && is_reference<int&>::value, ""); | |
90 | static_assert(!is_reference_v<int> && !is_reference<int>::value, ""); | |
91 | ||
92 | static_assert(is_arithmetic_v<int> && is_arithmetic<int>::value, ""); | |
93 | static_assert(!is_arithmetic_v<void*> && !is_arithmetic<void*>::value, ""); | |
94 | ||
95 | static_assert(is_fundamental_v<int> && is_fundamental<int>::value, ""); | |
96 | static_assert(!is_fundamental_v<EmptyFinal> | |
97 | && !is_fundamental<EmptyFinal>::value, ""); | |
98 | ||
99 | static_assert(is_object_v<int> && is_object<int>::value, ""); | |
100 | static_assert(!is_object_v<int&> && !is_object<int&>::value, ""); | |
101 | ||
102 | static_assert(is_scalar_v<int> && is_scalar<int>::value, ""); | |
103 | static_assert(!is_scalar_v<int&> && !is_scalar<int&>::value, ""); | |
104 | ||
105 | static_assert(is_compound_v<EmptyFinal> | |
106 | && is_compound<EmptyFinal>::value, ""); | |
107 | static_assert(!is_compound_v<int> && !is_compound<int>::value, ""); | |
108 | ||
109 | static_assert(is_member_pointer_v<int (EmptyFinal::*)> | |
110 | && is_member_pointer<int (EmptyFinal::*)>::value, ""); | |
111 | static_assert(!is_member_pointer_v<void*> | |
112 | && !is_member_pointer<void*>::value, ""); | |
113 | ||
114 | static_assert(is_const_v<const int> && is_const<const int>::value, ""); | |
115 | static_assert(!is_const_v<int> && !is_const<int>::value, ""); | |
116 | ||
117 | static_assert(is_volatile_v<volatile int> | |
118 | && is_volatile<volatile int>::value, ""); | |
119 | static_assert(!is_volatile_v<int> && !is_volatile<int>::value, ""); | |
120 | ||
121 | struct NType | |
122 | { | |
123 | NType(int); | |
124 | ~NType(); | |
125 | int i; | |
126 | private: | |
127 | NType(const NType&); | |
128 | NType& operator=(const NType&); | |
129 | int i2; | |
130 | }; | |
131 | ||
132 | static_assert(is_trivial_v<int> && is_trivial<int>::value, ""); | |
133 | static_assert(!is_trivial_v<NType> && !is_trivial<NType>::value, ""); | |
134 | ||
135 | static_assert(is_trivially_copyable_v<int> | |
136 | && is_trivially_copyable<int>::value, ""); | |
137 | static_assert(!is_trivially_copyable_v<NType> | |
138 | && !is_trivially_copyable<NType>::value, ""); | |
139 | ||
140 | static_assert(is_standard_layout_v<int> | |
141 | && is_standard_layout<int>::value, ""); | |
142 | static_assert(!is_standard_layout_v<NType> | |
143 | && !is_standard_layout<NType>::value, ""); | |
144 | ||
95edead9 | 145 | // Deprecated in C++20 |
137422c8 VV |
146 | static_assert(is_pod_v<int> |
147 | && is_pod<int>::value, ""); | |
148 | static_assert(!is_pod_v<NType> | |
149 | && !is_pod<NType>::value, ""); | |
150 | ||
24b54628 VV |
151 | #pragma GCC diagnostic push |
152 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
137422c8 VV |
153 | static_assert(is_literal_type_v<int> |
154 | && is_literal_type<int>::value, ""); | |
155 | static_assert(!is_literal_type_v<NType> | |
156 | && !is_literal_type<NType>::value, ""); | |
24b54628 | 157 | #pragma GCC diagnostic pop |
137422c8 VV |
158 | |
159 | static_assert(is_empty_v<EmptyFinal> | |
160 | && is_empty<EmptyFinal>::value, ""); | |
161 | static_assert(!is_empty_v<NType> | |
162 | && !is_empty<NType>::value, ""); | |
163 | ||
164 | struct Abstract {protected: virtual ~Abstract() = 0;}; | |
165 | struct Poly : Abstract {virtual ~Poly();}; | |
166 | ||
167 | static_assert(is_polymorphic_v<Poly> | |
168 | && is_polymorphic<Poly>::value, ""); | |
169 | static_assert(!is_polymorphic_v<EmptyFinal> | |
170 | && !is_polymorphic<EmptyFinal>::value, ""); | |
171 | ||
172 | ||
173 | ||
174 | static_assert(is_abstract_v<Abstract> | |
175 | && is_abstract<Abstract>::value, ""); | |
176 | static_assert(!is_abstract_v<EmptyFinal> | |
177 | && !is_abstract<EmptyFinal>::value, ""); | |
178 | ||
179 | static_assert(is_final_v<EmptyFinal> | |
180 | && is_final<EmptyFinal>::value, ""); | |
181 | static_assert(!is_final_v<Abstract> | |
182 | && !is_final<Abstract>::value, ""); | |
183 | ||
184 | static_assert(is_signed_v<int> && is_signed<int>::value, ""); | |
185 | static_assert(!is_signed_v<unsigned int> | |
186 | && !is_signed<unsigned int>::value, ""); | |
187 | ||
188 | static_assert(is_constructible_v<int, int> | |
189 | && is_constructible<int, int>::value, ""); | |
190 | static_assert(!is_constructible_v<int, void*> | |
191 | && !is_constructible<int, void*>::value, ""); | |
192 | ||
193 | static_assert(is_default_constructible_v<int> | |
194 | && is_default_constructible<int>::value, ""); | |
195 | static_assert(!is_default_constructible_v<NType> | |
196 | && !is_default_constructible<NType>::value, ""); | |
197 | ||
198 | static_assert(is_copy_constructible_v<int> | |
199 | && is_copy_constructible<int>::value, ""); | |
200 | static_assert(!is_copy_constructible_v<NType> | |
201 | && !is_copy_constructible<NType>::value, ""); | |
202 | ||
203 | static_assert(is_move_constructible_v<int> | |
204 | && is_copy_constructible<int>::value, ""); | |
205 | static_assert(!is_move_constructible_v<NType> | |
206 | && !is_copy_constructible<NType>::value, ""); | |
207 | ||
208 | static_assert(is_assignable_v<int&, int> | |
209 | && is_assignable<int&, int>::value, ""); | |
210 | static_assert(!is_assignable_v<int, int> | |
211 | && !is_assignable<int, int>::value, ""); | |
212 | ||
213 | static_assert(is_copy_assignable_v<int> | |
214 | && is_copy_assignable<int>::value, ""); | |
215 | static_assert(!is_copy_assignable_v<NType> | |
216 | && !is_copy_assignable<NType>::value, ""); | |
217 | ||
218 | static_assert(is_move_assignable_v<int> | |
219 | && is_move_assignable<int>::value, ""); | |
220 | static_assert(!is_move_assignable_v<NType> | |
221 | && !is_move_assignable<NType>::value, ""); | |
222 | ||
223 | static_assert(is_destructible_v<int> | |
224 | && is_destructible<int>::value, ""); | |
225 | static_assert(!is_destructible_v<Abstract> | |
226 | && !is_destructible<Abstract>::value, ""); | |
227 | ||
228 | static_assert(is_trivially_constructible_v<int, int> | |
229 | && is_trivially_constructible<int, int>::value, ""); | |
230 | static_assert(!is_trivially_constructible_v<NType, NType> | |
231 | && !is_trivially_constructible<NType, NType>::value, ""); | |
232 | ||
233 | static_assert(is_trivially_default_constructible_v<int> | |
234 | && is_trivially_default_constructible<int>::value, ""); | |
235 | static_assert(!is_trivially_default_constructible_v<NType> | |
236 | && !is_trivially_default_constructible<NType>::value, ""); | |
237 | ||
238 | static_assert(is_trivially_copy_constructible_v<int> | |
239 | && is_trivially_copy_constructible<int>::value, ""); | |
240 | static_assert(!is_trivially_copy_constructible_v<NType> | |
241 | && !is_trivially_copy_constructible<NType>::value, ""); | |
242 | ||
243 | static_assert(is_trivially_move_constructible_v<int> | |
244 | && is_trivially_move_constructible<int>::value, ""); | |
245 | static_assert(!is_trivially_move_constructible_v<NType> | |
246 | && !is_trivially_move_constructible<NType>::value, ""); | |
247 | ||
248 | static_assert(is_trivially_assignable_v<int&, int> | |
249 | && is_trivially_assignable<int&, int>::value, ""); | |
250 | static_assert(!is_trivially_assignable_v<NType, NType> | |
251 | && !is_trivially_assignable<NType, NType>::value, ""); | |
252 | ||
253 | static_assert(is_trivially_copy_assignable_v<int> | |
254 | && is_trivially_copy_assignable<int>::value, ""); | |
255 | static_assert(!is_trivially_copy_assignable_v<NType> | |
256 | && !is_trivially_copy_assignable<NType>::value, ""); | |
257 | ||
258 | static_assert(is_trivially_move_assignable_v<int> | |
259 | && is_trivially_move_assignable<int>::value, ""); | |
260 | static_assert(!is_trivially_move_assignable_v<NType> | |
261 | && !is_trivially_move_assignable<NType>::value, ""); | |
262 | ||
263 | static_assert(is_trivially_destructible_v<int> | |
264 | && is_trivially_destructible<int>::value, ""); | |
265 | static_assert(!is_trivially_destructible_v<Abstract> | |
266 | && !is_trivially_destructible<Abstract>::value, ""); | |
267 | ||
268 | static_assert(is_nothrow_constructible_v<int, int> | |
269 | && is_nothrow_constructible<int, int>::value, ""); | |
270 | static_assert(!is_nothrow_constructible_v<NType, NType> | |
271 | && !is_nothrow_constructible<NType, NType>::value, ""); | |
272 | ||
273 | static_assert(is_nothrow_default_constructible_v<int> | |
274 | && is_nothrow_default_constructible<int>::value, ""); | |
275 | static_assert(!is_nothrow_default_constructible_v<NType> | |
276 | && !is_nothrow_default_constructible<NType>::value, ""); | |
277 | ||
278 | static_assert(is_nothrow_copy_constructible_v<int> | |
279 | && is_nothrow_copy_constructible<int>::value, ""); | |
280 | static_assert(!is_nothrow_copy_constructible_v<NType> | |
281 | && !is_nothrow_copy_constructible<NType>::value, ""); | |
282 | ||
283 | static_assert(is_nothrow_move_constructible_v<int> | |
284 | && is_nothrow_move_constructible<int>::value, ""); | |
285 | static_assert(!is_nothrow_move_constructible_v<NType> | |
286 | && !is_nothrow_move_constructible<NType>::value, ""); | |
287 | ||
288 | static_assert(is_nothrow_assignable_v<int&, int> | |
289 | && is_nothrow_assignable<int&, int>::value, ""); | |
290 | static_assert(!is_nothrow_assignable_v<NType, NType> | |
291 | && !is_nothrow_assignable<NType, NType>::value, ""); | |
292 | ||
293 | static_assert(is_nothrow_copy_assignable_v<int> | |
294 | && is_nothrow_copy_assignable<int>::value, ""); | |
295 | static_assert(!is_nothrow_copy_assignable_v<NType> | |
296 | && !is_nothrow_copy_assignable<NType>::value, ""); | |
297 | ||
298 | static_assert(is_nothrow_move_assignable_v<int> | |
299 | && is_nothrow_move_assignable<int>::value, ""); | |
300 | static_assert(!is_nothrow_move_assignable_v<NType> | |
301 | && !is_nothrow_move_assignable<NType>::value, ""); | |
302 | ||
303 | static_assert(has_virtual_destructor_v<Abstract> | |
304 | && has_virtual_destructor<Abstract>::value, ""); | |
305 | static_assert(!has_virtual_destructor_v<NType> | |
306 | && !has_virtual_destructor<NType>::value, ""); | |
307 | ||
308 | static_assert(alignment_of_v<int> == alignof(int) | |
309 | && alignment_of<int>::value == alignof(int) , ""); | |
310 | ||
311 | static_assert(rank_v<int[1][1]> == rank<int[1][1]>::value, ""); | |
312 | ||
313 | static_assert(extent_v<int[1][2], 1> == 2 | |
314 | && extent<int[1][2], 1>::value == 2, ""); | |
315 | ||
316 | static_assert(is_same_v<int, int> && is_same<int, int>::value, ""); | |
317 | static_assert(!is_same_v<int, char> && !is_same<int, char>::value, ""); | |
318 | ||
319 | static_assert(is_base_of_v<Abstract, Poly> | |
320 | && is_base_of<Abstract, Poly>::value, ""); | |
321 | static_assert(!is_base_of_v<Abstract, NType> | |
322 | && !is_base_of<Abstract, NType>::value, ""); | |
323 | ||
324 | static_assert(is_convertible_v<int&, const int&> | |
325 | && is_convertible<int&, const int&>::value, ""); | |
326 | static_assert(!is_convertible_v<const int&, int&> | |
327 | && !is_convertible<const int&, int&>::value, ""); | |
328 | ||
329 | static_assert(negation_v<false_type>, ""); | |
330 | static_assert(!negation_v<true_type>, ""); | |
331 | static_assert(conjunction_v<>, ""); | |
332 | static_assert(!disjunction_v<>, ""); | |
333 | static_assert(conjunction_v<true_type>, ""); | |
334 | static_assert(!conjunction_v<false_type>, ""); | |
335 | static_assert(disjunction_v<true_type>, ""); | |
336 | static_assert(!disjunction_v<false_type>, ""); | |
337 | static_assert(conjunction_v<true_type, true_type>, ""); | |
338 | static_assert(!conjunction_v<true_type, false_type>, ""); | |
339 | static_assert(disjunction_v<false_type, true_type>, ""); | |
340 | static_assert(!disjunction_v<false_type, false_type>, ""); | |
341 | static_assert(conjunction_v<true_type, true_type, | |
342 | true_type>, ""); | |
343 | static_assert(!conjunction_v<true_type, true_type, | |
344 | false_type>, ""); | |
345 | static_assert(disjunction_v<false_type, false_type, | |
346 | true_type>, ""); | |
347 | static_assert(!disjunction_v<false_type, false_type, | |
348 | false_type>, ""); |