]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/type_traits/value.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / type_traits / value.cc
1 // { dg-do compile { target c++14 } }
2 // { dg-additional-options "-Wno-deprecated" { target { c++2a } } }
3
4 // Copyright (C) 2014-2023 Free Software Foundation, Inc.
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
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 #include <experimental/type_traits>
22
23 using std::true_type;
24 using std::false_type;
25 using std::nullptr_t;
26 using std::is_void;
27 using std::is_null_pointer;
28 using std::is_integral;
29 using std::is_floating_point;
30 using std::is_array;
31 using std::is_pointer;
32 using std::is_lvalue_reference;
33 using std::is_rvalue_reference;
34 using std::is_member_object_pointer;
35 using std::is_member_function_pointer;
36 using std::is_enum;
37 using std::is_union;
38 using std::is_class;
39 using std::is_function;
40 using std::is_reference;
41 using std::is_arithmetic;
42 using std::is_fundamental;
43 using std::is_object;
44 using std::is_scalar;
45 using std::is_compound;
46 using std::is_member_pointer;
47 using std::is_const;
48 using std::is_volatile;
49 using std::is_trivial;
50 using std::is_trivially_copyable;
51 using std::is_standard_layout;
52 using std::is_pod;
53 using std::is_literal_type;
54 using std::is_empty;
55 using std::is_polymorphic;
56 using std::is_abstract;
57 using std::is_final;
58 using std::is_signed;
59 using std::is_constructible;
60 using std::is_default_constructible;
61 using std::is_copy_constructible;
62 using std::is_move_constructible;
63 using std::is_assignable;
64 using std::is_copy_assignable;
65 using std::is_move_assignable;
66 using std::is_destructible;
67 using std::is_trivially_constructible;
68 using std::is_trivially_default_constructible;
69 using std::is_trivially_copy_constructible;
70 using std::is_trivially_move_constructible;
71 using std::is_trivially_assignable;
72 using std::is_trivially_copy_assignable;
73 using std::is_trivially_move_assignable;
74 using std::is_trivially_destructible;
75 using std::is_nothrow_constructible;
76 using std::is_nothrow_default_constructible;
77 using std::is_nothrow_copy_constructible;
78 using std::is_nothrow_move_constructible;
79 using std::is_nothrow_assignable;
80 using std::is_nothrow_copy_assignable;
81 using std::is_nothrow_move_assignable;
82 using std::is_nothrow_destructible;
83 using std::has_virtual_destructor;
84 using std::alignment_of;
85 using std::rank;
86 using std::extent;
87 using std::is_same;
88 using std::is_base_of;
89 using std::is_convertible;
90 using namespace std::experimental;
91
92 // These tests are rather simple, the front-end tests already test
93 // variable templates, and the library tests for the underlying
94 // traits are more elaborate. These are just simple sanity tests.
95
96 static_assert(is_void_v<void> && is_void<void>::value, "");
97 static_assert(!is_void_v<int> && !is_void<int>::value, "");
98
99 static_assert(is_null_pointer_v<nullptr_t>
100 && is_null_pointer<nullptr_t>::value, "");
101 static_assert(!is_null_pointer_v<void*>
102 && !is_null_pointer<void*>::value, "");
103
104 static_assert(is_integral_v<int> && is_integral<int>::value, "");
105 static_assert(!is_integral_v<int*> && !is_integral<int*>::value, "");
106
107 static_assert(is_floating_point_v<float>
108 && is_floating_point<float>::value, "");
109 static_assert(!is_floating_point_v<int>
110 && !is_floating_point<int>::value, "");
111
112 static_assert(is_array_v<char[42]> && is_array<char[42]>::value, "");
113 static_assert(!is_array_v<char*> && !is_array<char*>::value, "");
114
115 static_assert(is_pointer_v<int*> && is_pointer<int*>::value, "");
116 static_assert(!is_pointer_v<int> && !is_pointer<int>::value, "");
117
118 static_assert(is_lvalue_reference_v<int&>
119 && is_lvalue_reference<int&>::value, "");
120 static_assert(!is_lvalue_reference_v<int>
121 && !is_lvalue_reference<int>::value, "");
122
123 static_assert(is_rvalue_reference_v<int&&>
124 && is_rvalue_reference<int&&>::value, "");
125 static_assert(!is_rvalue_reference_v<int>
126 && !is_rvalue_reference<int>::value, "");
127
128 struct EmptyFinal final {};
129
130 static_assert(is_member_object_pointer_v<int (EmptyFinal::*)>
131 && is_member_object_pointer<int (EmptyFinal::*)>::value, "");
132 static_assert(!is_member_object_pointer_v<void*>
133 && !is_member_object_pointer<void*>::value, "");
134
135 static_assert(is_member_function_pointer_v<int (EmptyFinal::*)()>
136 && is_member_function_pointer<int (EmptyFinal::*)()>::value, "");
137 static_assert(!is_member_function_pointer_v<void*>
138 && !is_member_function_pointer<void*>::value, "");
139
140 enum Enum {};
141
142 static_assert(is_enum_v<Enum> && is_enum<Enum>::value, "");
143 static_assert(!is_enum_v<int> && !is_enum<int>::value, "");
144
145 union Union;
146
147 static_assert(is_union_v<Union> && is_union<Union>::value, "");
148 static_assert(!is_union_v<int> && !is_union<int>::value, "");
149
150 static_assert(is_class_v<EmptyFinal> && is_class<EmptyFinal>::value, "");
151 static_assert(!is_class_v<int> && !is_class<int>::value, "");
152
153 static_assert(is_function_v<void()> && is_function<void()>::value, "");
154 static_assert(!is_function_v<void(*)()> && !is_function<void(*)()>::value, "");
155
156 static_assert(is_reference_v<int&> && is_reference<int&>::value, "");
157 static_assert(!is_reference_v<int> && !is_reference<int>::value, "");
158
159 static_assert(is_arithmetic_v<int> && is_arithmetic<int>::value, "");
160 static_assert(!is_arithmetic_v<void*> && !is_arithmetic<void*>::value, "");
161
162 static_assert(is_fundamental_v<int> && is_fundamental<int>::value, "");
163 static_assert(!is_fundamental_v<EmptyFinal>
164 && !is_fundamental<EmptyFinal>::value, "");
165
166 static_assert(is_object_v<int> && is_object<int>::value, "");
167 static_assert(!is_object_v<int&> && !is_object<int&>::value, "");
168
169 static_assert(is_scalar_v<int> && is_scalar<int>::value, "");
170 static_assert(!is_scalar_v<int&> && !is_scalar<int&>::value, "");
171
172 static_assert(is_compound_v<EmptyFinal>
173 && is_compound<EmptyFinal>::value, "");
174 static_assert(!is_compound_v<int> && !is_compound<int>::value, "");
175
176 static_assert(is_member_pointer_v<int (EmptyFinal::*)>
177 && is_member_pointer<int (EmptyFinal::*)>::value, "");
178 static_assert(!is_member_pointer_v<void*>
179 && !is_member_pointer<void*>::value, "");
180
181 static_assert(is_const_v<const int> && is_const<const int>::value, "");
182 static_assert(!is_const_v<int> && !is_const<int>::value, "");
183
184 static_assert(is_volatile_v<volatile int>
185 && is_volatile<volatile int>::value, "");
186 static_assert(!is_volatile_v<int> && !is_volatile<int>::value, "");
187
188 struct NType
189 {
190 NType(int);
191 ~NType();
192 int i;
193 private:
194 NType(const NType&);
195 NType& operator=(const NType&);
196 int i2;
197 };
198
199 static_assert(is_trivial_v<int> && is_trivial<int>::value, "");
200 static_assert(!is_trivial_v<NType> && !is_trivial<NType>::value, "");
201
202 static_assert(is_trivially_copyable_v<int>
203 && is_trivially_copyable<int>::value, "");
204 static_assert(!is_trivially_copyable_v<NType>
205 && !is_trivially_copyable<NType>::value, "");
206
207 static_assert(is_standard_layout_v<int>
208 && is_standard_layout<int>::value, "");
209 static_assert(!is_standard_layout_v<NType>
210 && !is_standard_layout<NType>::value, "");
211
212 static_assert(is_pod_v<int>
213 && is_pod<int>::value, "");
214 static_assert(!is_pod_v<NType>
215 && !is_pod<NType>::value, "");
216
217 #pragma GCC diagnostic push
218 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
219 static_assert(is_literal_type_v<int>
220 && is_literal_type<int>::value, "");
221 static_assert(!is_literal_type_v<NType>
222 && !is_literal_type<NType>::value, "");
223 #pragma GCC diagnostic pop
224
225 static_assert(is_empty_v<EmptyFinal>
226 && is_empty<EmptyFinal>::value, "");
227 static_assert(!is_empty_v<NType>
228 && !is_empty<NType>::value, "");
229
230 struct Abstract {protected: virtual ~Abstract() = 0;};
231 struct Poly : Abstract {virtual ~Poly();};
232
233 static_assert(is_polymorphic_v<Poly>
234 && is_polymorphic<Poly>::value, "");
235 static_assert(!is_polymorphic_v<EmptyFinal>
236 && !is_polymorphic<EmptyFinal>::value, "");
237
238
239
240 static_assert(is_abstract_v<Abstract>
241 && is_abstract<Abstract>::value, "");
242 static_assert(!is_abstract_v<EmptyFinal>
243 && !is_abstract<EmptyFinal>::value, "");
244
245 static_assert(is_final_v<EmptyFinal>
246 && is_final<EmptyFinal>::value, "");
247 static_assert(!is_final_v<Abstract>
248 && !is_final<Abstract>::value, "");
249
250 static_assert(is_signed_v<int> && is_signed<int>::value, "");
251 static_assert(!is_signed_v<unsigned int>
252 && !is_signed<unsigned int>::value, "");
253
254 static_assert(is_constructible_v<int, int>
255 && is_constructible<int, int>::value, "");
256 static_assert(!is_constructible_v<int, void*>
257 && !is_constructible<int, void*>::value, "");
258
259 static_assert(is_default_constructible_v<int>
260 && is_default_constructible<int>::value, "");
261 static_assert(!is_default_constructible_v<NType>
262 && !is_default_constructible<NType>::value, "");
263
264 static_assert(is_copy_constructible_v<int>
265 && is_copy_constructible<int>::value, "");
266 static_assert(!is_copy_constructible_v<NType>
267 && !is_copy_constructible<NType>::value, "");
268
269 static_assert(is_move_constructible_v<int>
270 && is_copy_constructible<int>::value, "");
271 static_assert(!is_move_constructible_v<NType>
272 && !is_copy_constructible<NType>::value, "");
273
274 static_assert(is_assignable_v<int&, int>
275 && is_assignable<int&, int>::value, "");
276 static_assert(!is_assignable_v<int, int>
277 && !is_assignable<int, int>::value, "");
278
279 static_assert(is_copy_assignable_v<int>
280 && is_copy_assignable<int>::value, "");
281 static_assert(!is_copy_assignable_v<NType>
282 && !is_copy_assignable<NType>::value, "");
283
284 static_assert(is_move_assignable_v<int>
285 && is_move_assignable<int>::value, "");
286 static_assert(!is_move_assignable_v<NType>
287 && !is_move_assignable<NType>::value, "");
288
289 static_assert(is_destructible_v<int>
290 && is_destructible<int>::value, "");
291 static_assert(!is_destructible_v<Abstract>
292 && !is_destructible<Abstract>::value, "");
293
294 static_assert(is_trivially_constructible_v<int, int>
295 && is_trivially_constructible<int, int>::value, "");
296 static_assert(!is_trivially_constructible_v<NType, NType>
297 && !is_trivially_constructible<NType, NType>::value, "");
298
299 static_assert(is_trivially_default_constructible_v<int>
300 && is_trivially_default_constructible<int>::value, "");
301 static_assert(!is_trivially_default_constructible_v<NType>
302 && !is_trivially_default_constructible<NType>::value, "");
303
304 static_assert(is_trivially_copy_constructible_v<int>
305 && is_trivially_copy_constructible<int>::value, "");
306 static_assert(!is_trivially_copy_constructible_v<NType>
307 && !is_trivially_copy_constructible<NType>::value, "");
308
309 static_assert(is_trivially_move_constructible_v<int>
310 && is_trivially_move_constructible<int>::value, "");
311 static_assert(!is_trivially_move_constructible_v<NType>
312 && !is_trivially_move_constructible<NType>::value, "");
313
314 static_assert(is_trivially_assignable_v<int&, int>
315 && is_trivially_assignable<int&, int>::value, "");
316 static_assert(!is_trivially_assignable_v<NType, NType>
317 && !is_trivially_assignable<NType, NType>::value, "");
318
319 static_assert(is_trivially_copy_assignable_v<int>
320 && is_trivially_copy_assignable<int>::value, "");
321 static_assert(!is_trivially_copy_assignable_v<NType>
322 && !is_trivially_copy_assignable<NType>::value, "");
323
324 static_assert(is_trivially_move_assignable_v<int>
325 && is_trivially_move_assignable<int>::value, "");
326 static_assert(!is_trivially_move_assignable_v<NType>
327 && !is_trivially_move_assignable<NType>::value, "");
328
329 static_assert(is_trivially_destructible_v<int>
330 && is_trivially_destructible<int>::value, "");
331 static_assert(!is_trivially_destructible_v<Abstract>
332 && !is_trivially_destructible<Abstract>::value, "");
333
334 static_assert(is_nothrow_constructible_v<int, int>
335 && is_nothrow_constructible<int, int>::value, "");
336 static_assert(!is_nothrow_constructible_v<NType, NType>
337 && !is_nothrow_constructible<NType, NType>::value, "");
338
339 static_assert(is_nothrow_default_constructible_v<int>
340 && is_nothrow_default_constructible<int>::value, "");
341 static_assert(!is_nothrow_default_constructible_v<NType>
342 && !is_nothrow_default_constructible<NType>::value, "");
343
344 static_assert(is_nothrow_copy_constructible_v<int>
345 && is_nothrow_copy_constructible<int>::value, "");
346 static_assert(!is_nothrow_copy_constructible_v<NType>
347 && !is_nothrow_copy_constructible<NType>::value, "");
348
349 static_assert(is_nothrow_move_constructible_v<int>
350 && is_nothrow_move_constructible<int>::value, "");
351 static_assert(!is_nothrow_move_constructible_v<NType>
352 && !is_nothrow_move_constructible<NType>::value, "");
353
354 static_assert(is_nothrow_assignable_v<int&, int>
355 && is_nothrow_assignable<int&, int>::value, "");
356 static_assert(!is_nothrow_assignable_v<NType, NType>
357 && !is_nothrow_assignable<NType, NType>::value, "");
358
359 static_assert(is_nothrow_copy_assignable_v<int>
360 && is_nothrow_copy_assignable<int>::value, "");
361 static_assert(!is_nothrow_copy_assignable_v<NType>
362 && !is_nothrow_copy_assignable<NType>::value, "");
363
364 static_assert(is_nothrow_move_assignable_v<int>
365 && is_nothrow_move_assignable<int>::value, "");
366 static_assert(!is_nothrow_move_assignable_v<NType>
367 && !is_nothrow_move_assignable<NType>::value, "");
368
369 static_assert(has_virtual_destructor_v<Abstract>
370 && has_virtual_destructor<Abstract>::value, "");
371 static_assert(!has_virtual_destructor_v<NType>
372 && !has_virtual_destructor<NType>::value, "");
373
374 static_assert(alignment_of_v<int> == alignof(int)
375 && alignment_of<int>::value == alignof(int) , "");
376
377 static_assert(rank_v<int[1][1]> == rank<int[1][1]>::value, "");
378
379 static_assert(extent_v<int[1][2], 1> == 2
380 && extent<int[1][2], 1>::value == 2, "");
381
382 static_assert(is_same_v<int, int> && is_same<int, int>::value, "");
383 static_assert(!is_same_v<int, char> && !is_same<int, char>::value, "");
384
385 static_assert(is_base_of_v<Abstract, Poly>
386 && is_base_of<Abstract, Poly>::value, "");
387 static_assert(!is_base_of_v<Abstract, NType>
388 && !is_base_of<Abstract, NType>::value, "");
389
390 static_assert(is_convertible_v<int&, const int&>
391 && is_convertible<int&, const int&>::value, "");
392 static_assert(!is_convertible_v<const int&, int&>
393 && !is_convertible<const int&, int&>::value, "");
394
395 static_assert(negation_v<false_type>, "");
396 static_assert(!negation_v<true_type>, "");
397 static_assert(conjunction_v<>, "");
398 static_assert(!disjunction_v<>, "");
399 static_assert(conjunction_v<true_type>, "");
400 static_assert(!conjunction_v<false_type>, "");
401 static_assert(disjunction_v<true_type>, "");
402 static_assert(!disjunction_v<false_type>, "");
403 static_assert(conjunction_v<true_type, true_type>, "");
404 static_assert(!conjunction_v<true_type, false_type>, "");
405 static_assert(disjunction_v<false_type, true_type>, "");
406 static_assert(!disjunction_v<false_type, false_type>, "");
407 static_assert(conjunction_v<true_type, true_type,
408 true_type>, "");
409 static_assert(!conjunction_v<true_type, true_type,
410 false_type>, "");
411 static_assert(disjunction_v<false_type, false_type,
412 true_type>, "");
413 static_assert(!disjunction_v<false_type, false_type,
414 false_type>, "");