1 // { dg-do compile { target c++14 } }
2 // { dg-additional-options "-Wno-deprecated" { target { c++2a } } }
4 // Copyright (C) 2014-2023 Free Software Foundation, Inc.
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)
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.
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/>.
21 #include <experimental/type_traits>
24 using std::false_type
;
27 using std::is_null_pointer
;
28 using std::is_integral
;
29 using std::is_floating_point
;
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
;
39 using std::is_function
;
40 using std::is_reference
;
41 using std::is_arithmetic
;
42 using std::is_fundamental
;
45 using std::is_compound
;
46 using std::is_member_pointer
;
48 using std::is_volatile
;
49 using std::is_trivial
;
50 using std::is_trivially_copyable
;
51 using std::is_standard_layout
;
53 using std::is_literal_type
;
55 using std::is_polymorphic
;
56 using std::is_abstract
;
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
;
88 using std::is_base_of
;
89 using std::is_convertible
;
90 using namespace std::experimental
;
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.
96 static_assert(is_void_v
<void> && is_void
<void>::value
, "");
97 static_assert(!is_void_v
<int> && !is_void
<int>::value
, "");
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
, "");
104 static_assert(is_integral_v
<int> && is_integral
<int>::value
, "");
105 static_assert(!is_integral_v
<int*> && !is_integral
<int*>::value
, "");
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
, "");
112 static_assert(is_array_v
<char[42]> && is_array
<char[42]>::value
, "");
113 static_assert(!is_array_v
<char*> && !is_array
<char*>::value
, "");
115 static_assert(is_pointer_v
<int*> && is_pointer
<int*>::value
, "");
116 static_assert(!is_pointer_v
<int> && !is_pointer
<int>::value
, "");
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
, "");
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
, "");
128 struct EmptyFinal final
{};
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
, "");
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
, "");
142 static_assert(is_enum_v
<Enum
> && is_enum
<Enum
>::value
, "");
143 static_assert(!is_enum_v
<int> && !is_enum
<int>::value
, "");
147 static_assert(is_union_v
<Union
> && is_union
<Union
>::value
, "");
148 static_assert(!is_union_v
<int> && !is_union
<int>::value
, "");
150 static_assert(is_class_v
<EmptyFinal
> && is_class
<EmptyFinal
>::value
, "");
151 static_assert(!is_class_v
<int> && !is_class
<int>::value
, "");
153 static_assert(is_function_v
<void()> && is_function
<void()>::value
, "");
154 static_assert(!is_function_v
<void(*)()> && !is_function
<void(*)()>::value
, "");
156 static_assert(is_reference_v
<int&> && is_reference
<int&>::value
, "");
157 static_assert(!is_reference_v
<int> && !is_reference
<int>::value
, "");
159 static_assert(is_arithmetic_v
<int> && is_arithmetic
<int>::value
, "");
160 static_assert(!is_arithmetic_v
<void*> && !is_arithmetic
<void*>::value
, "");
162 static_assert(is_fundamental_v
<int> && is_fundamental
<int>::value
, "");
163 static_assert(!is_fundamental_v
<EmptyFinal
>
164 && !is_fundamental
<EmptyFinal
>::value
, "");
166 static_assert(is_object_v
<int> && is_object
<int>::value
, "");
167 static_assert(!is_object_v
<int&> && !is_object
<int&>::value
, "");
169 static_assert(is_scalar_v
<int> && is_scalar
<int>::value
, "");
170 static_assert(!is_scalar_v
<int&> && !is_scalar
<int&>::value
, "");
172 static_assert(is_compound_v
<EmptyFinal
>
173 && is_compound
<EmptyFinal
>::value
, "");
174 static_assert(!is_compound_v
<int> && !is_compound
<int>::value
, "");
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
, "");
181 static_assert(is_const_v
<const int> && is_const
<const int>::value
, "");
182 static_assert(!is_const_v
<int> && !is_const
<int>::value
, "");
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
, "");
195 NType
& operator=(const NType
&);
199 static_assert(is_trivial_v
<int> && is_trivial
<int>::value
, "");
200 static_assert(!is_trivial_v
<NType
> && !is_trivial
<NType
>::value
, "");
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
, "");
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
, "");
212 static_assert(is_pod_v
<int>
213 && is_pod
<int>::value
, "");
214 static_assert(!is_pod_v
<NType
>
215 && !is_pod
<NType
>::value
, "");
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
225 static_assert(is_empty_v
<EmptyFinal
>
226 && is_empty
<EmptyFinal
>::value
, "");
227 static_assert(!is_empty_v
<NType
>
228 && !is_empty
<NType
>::value
, "");
230 struct Abstract
{protected: virtual ~Abstract() = 0;};
231 struct Poly
: Abstract
{virtual ~Poly();};
233 static_assert(is_polymorphic_v
<Poly
>
234 && is_polymorphic
<Poly
>::value
, "");
235 static_assert(!is_polymorphic_v
<EmptyFinal
>
236 && !is_polymorphic
<EmptyFinal
>::value
, "");
240 static_assert(is_abstract_v
<Abstract
>
241 && is_abstract
<Abstract
>::value
, "");
242 static_assert(!is_abstract_v
<EmptyFinal
>
243 && !is_abstract
<EmptyFinal
>::value
, "");
245 static_assert(is_final_v
<EmptyFinal
>
246 && is_final
<EmptyFinal
>::value
, "");
247 static_assert(!is_final_v
<Abstract
>
248 && !is_final
<Abstract
>::value
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
289 static_assert(is_destructible_v
<int>
290 && is_destructible
<int>::value
, "");
291 static_assert(!is_destructible_v
<Abstract
>
292 && !is_destructible
<Abstract
>::value
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
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
, "");
374 static_assert(alignment_of_v
<int> == alignof(int)
375 && alignment_of
<int>::value
== alignof(int) , "");
377 static_assert(rank_v
<int[1][1]> == rank
<int[1][1]>::value
, "");
379 static_assert(extent_v
<int[1][2], 1> == 2
380 && extent
<int[1][2], 1>::value
== 2, "");
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
, "");
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
, "");
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
, "");
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
,
409 static_assert(!conjunction_v
<true_type
, true_type
,
411 static_assert(disjunction_v
<false_type
, false_type
,
413 static_assert(!disjunction_v
<false_type
, false_type
,