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