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