]>
Commit | Line | Data |
---|---|---|
fd1e1726 | 1 | // -*- C++ -*- |
f92ab29f | 2 | // typelist for the C++ library testsuite. |
fd1e1726 | 3 | // |
8d9254fc | 4 | // Copyright (C) 2005-2020 Free Software Foundation, Inc. |
fd1e1726 BK |
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 | |
748086b7 | 9 | // Free Software Foundation; either version 3, or (at your option) |
fd1e1726 BK |
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 | |
748086b7 JJ |
18 | // with this library; see the file COPYING3. If not see |
19 | // <http://www.gnu.org/licenses/>. | |
fd1e1726 | 20 | // |
fd1e1726 BK |
21 | |
22 | #ifndef _TESTSUITE_COMMON_TYPES_H | |
23 | #define _TESTSUITE_COMMON_TYPES_H 1 | |
24 | ||
fd1e1726 BK |
25 | #include <ext/typelist.h> |
26 | ||
27 | #include <ext/new_allocator.h> | |
28 | #include <ext/malloc_allocator.h> | |
29 | #include <ext/mt_allocator.h> | |
30 | #include <ext/bitmap_allocator.h> | |
31 | #include <ext/pool_allocator.h> | |
32 | ||
bcc0edbb PC |
33 | #include <algorithm> |
34 | ||
fd1e1726 BK |
35 | #include <vector> |
36 | #include <list> | |
37 | #include <deque> | |
38 | #include <string> | |
237526dd | 39 | #include <limits> |
fd1e1726 BK |
40 | |
41 | #include <map> | |
42 | #include <set> | |
0c3de900 | 43 | #include <tr1/functional> |
fd1e1726 BK |
44 | #include <tr1/unordered_map> |
45 | #include <tr1/unordered_set> | |
46 | ||
734f5023 | 47 | #if __cplusplus >= 201103L |
afd88205 | 48 | #include <atomic> |
50ce8d3d | 49 | #include <type_traits> |
d466a7e2 BK |
50 | #endif |
51 | ||
fd1e1726 BK |
52 | namespace __gnu_test |
53 | { | |
59019b42 | 54 | using __gnu_cxx::typelist::null_type; |
cad367a6 BK |
55 | using __gnu_cxx::typelist::node; |
56 | using __gnu_cxx::typelist::transform; | |
57 | using __gnu_cxx::typelist::append; | |
fd1e1726 BK |
58 | |
59 | // All the allocators to test. | |
60 | template<typename Tp, bool Thread> | |
61 | struct allocator_policies | |
62 | { | |
63 | typedef Tp value_type; | |
64 | typedef __gnu_cxx::new_allocator<Tp> a1; | |
65 | typedef __gnu_cxx::malloc_allocator<Tp> a2; | |
66 | typedef __gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, Thread> pool_policy; | |
67 | typedef __gnu_cxx::__mt_alloc<Tp, pool_policy> a3; | |
68 | typedef __gnu_cxx::bitmap_allocator<Tp> a4; | |
69 | typedef __gnu_cxx::__pool_alloc<Tp> a5; | |
cad367a6 | 70 | typedef node<_GLIBCXX_TYPELIST_CHAIN5(a1, a2, a3, a4, a5)> type; |
fd1e1726 BK |
71 | }; |
72 | ||
73 | // Typelists for vector, string, list, deque. | |
74 | // XXX should just use template templates | |
75 | template<typename Tp, bool Thread> | |
76 | struct vectors | |
77 | { | |
78 | typedef Tp value_type; | |
79 | ||
80 | template<typename Tl> | |
81 | struct vector_shell | |
82 | { | |
83 | typedef Tl allocator_type; | |
84 | typedef std::vector<value_type, allocator_type> type; | |
85 | }; | |
86 | ||
87 | typedef allocator_policies<value_type, Thread> allocator_types; | |
88 | typedef typename allocator_types::type allocator_typelist; | |
89 | typedef typename transform<allocator_typelist, vector_shell>::type type; | |
90 | }; | |
91 | ||
92 | template<typename Tp, bool Thread> | |
93 | struct lists | |
94 | { | |
95 | typedef Tp value_type; | |
96 | ||
97 | template<typename Tl> | |
98 | struct list_shell | |
99 | { | |
100 | typedef Tl allocator_type; | |
101 | typedef std::list<value_type, allocator_type> type; | |
102 | }; | |
103 | ||
104 | typedef allocator_policies<value_type, Thread> allocator_types; | |
105 | typedef typename allocator_types::type allocator_typelist; | |
106 | typedef typename transform<allocator_typelist, list_shell>::type type; | |
107 | }; | |
108 | ||
109 | template<typename Tp, bool Thread> | |
110 | struct deques | |
111 | { | |
112 | typedef Tp value_type; | |
113 | ||
114 | template<typename Tl> | |
115 | struct deque_shell | |
116 | { | |
117 | typedef Tl allocator_type; | |
118 | typedef std::deque<value_type, allocator_type> type; | |
119 | }; | |
120 | ||
121 | typedef allocator_policies<value_type, Thread> allocator_types; | |
122 | typedef typename allocator_types::type allocator_typelist; | |
123 | typedef typename transform<allocator_typelist, deque_shell>::type type; | |
124 | }; | |
125 | ||
126 | template<typename Tp, bool Thread> | |
127 | struct strings | |
128 | { | |
129 | typedef Tp value_type; | |
130 | ||
131 | template<typename Tl> | |
132 | struct string_shell | |
133 | { | |
134 | typedef Tl allocator_type; | |
135 | typedef std::char_traits<value_type> traits_type; | |
136 | typedef std::basic_string<value_type, traits_type, allocator_type> type; | |
137 | }; | |
138 | ||
139 | typedef allocator_policies<value_type, Thread> allocator_types; | |
140 | typedef typename allocator_types::type allocator_typelist; | |
141 | typedef typename transform<allocator_typelist, string_shell>::type type; | |
142 | }; | |
143 | ||
144 | // A typelist of vector, list, deque, and string all instantiated | |
145 | // with each of the allocator policies. | |
146 | template<typename Tp, bool Thread> | |
147 | struct sequence_containers | |
148 | { | |
149 | typedef Tp value_type; | |
150 | ||
151 | typedef typename vectors<value_type, Thread>::type vector_typelist; | |
152 | typedef typename lists<value_type, Thread>::type list_typelist; | |
153 | typedef typename deques<value_type, Thread>::type deque_typelist; | |
154 | typedef typename strings<value_type, Thread>::type string_typelist; | |
155 | ||
156 | typedef typename append<vector_typelist, list_typelist>::type a1; | |
157 | typedef typename append<deque_typelist, string_typelist>::type a2; | |
158 | typedef typename append<a1, a2>::type type; | |
159 | }; | |
160 | ||
0c3de900 | 161 | // Typelists for map, set, unordered_set, unordered_map. |
fd1e1726 BK |
162 | template<typename Tp, bool Thread> |
163 | struct maps | |
164 | { | |
165 | typedef Tp value_type; | |
166 | typedef Tp key_type; | |
167 | typedef std::pair<const key_type, value_type> pair_type; | |
168 | typedef std::less<key_type> compare_function; | |
169 | ||
170 | template<typename Tl> | |
171 | struct container | |
172 | { | |
173 | typedef Tl allocator_type; | |
174 | typedef std::map<key_type, value_type, compare_function, allocator_type> type; | |
175 | }; | |
176 | ||
177 | typedef allocator_policies<pair_type, Thread> allocator_types; | |
178 | typedef typename allocator_types::type allocator_typelist; | |
179 | typedef typename transform<allocator_typelist, container>::type type; | |
180 | }; | |
181 | ||
fd1e1726 BK |
182 | template<typename Tp, bool Thread> |
183 | struct unordered_maps | |
184 | { | |
185 | typedef Tp value_type; | |
186 | typedef Tp key_type; | |
187 | typedef std::pair<const key_type, value_type> pair_type; | |
188 | typedef std::tr1::hash<key_type> hash_function; | |
189 | typedef std::equal_to<key_type> equality_function; | |
190 | ||
191 | template<typename Tl> | |
192 | struct container | |
193 | { | |
194 | typedef Tl allocator_type; | |
195 | typedef std::tr1::unordered_map<key_type, value_type, hash_function, equality_function, allocator_type> type; | |
196 | }; | |
197 | ||
198 | typedef allocator_policies<pair_type, Thread> allocator_types; | |
199 | typedef typename allocator_types::type allocator_typelist; | |
200 | typedef typename transform<allocator_typelist, container>::type type; | |
201 | }; | |
202 | ||
203 | template<typename Tp, bool Thread> | |
204 | struct sets | |
205 | { | |
206 | typedef Tp value_type; | |
207 | typedef Tp key_type; | |
208 | typedef std::less<key_type> compare_function; | |
209 | ||
210 | template<typename Tl> | |
211 | struct container | |
212 | { | |
213 | typedef Tl allocator_type; | |
214 | typedef std::set<key_type, compare_function, allocator_type> type; | |
215 | }; | |
216 | ||
217 | typedef allocator_policies<key_type, Thread> allocator_types; | |
218 | typedef typename allocator_types::type allocator_typelist; | |
219 | typedef typename transform<allocator_typelist, container>::type type; | |
220 | }; | |
221 | ||
fd1e1726 BK |
222 | template<typename Tp, bool Thread> |
223 | struct unordered_sets | |
224 | { | |
225 | typedef Tp value_type; | |
226 | typedef Tp key_type; | |
227 | typedef std::tr1::hash<key_type> hash_function; | |
228 | typedef std::equal_to<key_type> equality_function; | |
229 | ||
230 | template<typename Tl> | |
231 | struct container | |
232 | { | |
233 | typedef Tl allocator_type; | |
234 | typedef std::tr1::unordered_set<key_type, hash_function, equality_function, allocator_type> type; | |
235 | }; | |
236 | ||
237 | typedef allocator_policies<key_type, Thread> allocator_types; | |
238 | typedef typename allocator_types::type allocator_typelist; | |
239 | typedef typename transform<allocator_typelist, container>::type type; | |
240 | }; | |
241 | ||
242 | ||
243 | // A typelist of all associated container types, with each of the | |
244 | // allocator policies. | |
245 | template<typename Tp, bool Thread> | |
246 | struct associative_containers | |
247 | { | |
248 | typedef Tp value_type; | |
249 | ||
250 | typedef typename maps<value_type, Thread>::type map_typelist; | |
251 | typedef typename sets<value_type, Thread>::type set_typelist; | |
fd1e1726 BK |
252 | typedef typename unordered_maps<value_type, Thread>::type unordered_map_typelist; |
253 | typedef typename unordered_sets<value_type, Thread>::type unordered_set_typelist; | |
254 | ||
0c3de900 BK |
255 | typedef typename append<map_typelist, unordered_map_typelist>::type a1; |
256 | typedef typename append<set_typelist, unordered_set_typelist>::type a2; | |
257 | typedef typename append<a1, a2>::type type; | |
fd1e1726 | 258 | }; |
d466a7e2 | 259 | |
12bfa8bd | 260 | // A typelist of all standard integral types. |
d466a7e2 BK |
261 | struct integral_types |
262 | { | |
263 | typedef bool a1; | |
264 | typedef char a2; | |
265 | typedef signed char a3; | |
266 | typedef unsigned char a4; | |
267 | typedef short a5; | |
268 | typedef unsigned short a6; | |
269 | typedef int a7; | |
270 | typedef unsigned int a8; | |
271 | typedef long a9; | |
272 | typedef unsigned long a10; | |
273 | typedef long long a11; | |
274 | typedef unsigned long long a12; | |
275 | typedef wchar_t a13; | |
59019b42 TH |
276 | typedef node<_GLIBCXX_TYPELIST_CHAIN13(a1, a2, a3, a4, a5, a6, a7, a8, a9, |
277 | a10, a11, a12, a13)> basic_typelist; | |
734f5023 | 278 | #if __cplusplus >= 201103L |
50ce8d3d BK |
279 | typedef char16_t a14; |
280 | typedef char32_t a15; | |
59019b42 | 281 | typedef node<_GLIBCXX_TYPELIST_CHAIN2(a14, a15)> cxx11_typelist; |
50ce8d3d | 282 | #else |
59019b42 TH |
283 | typedef node<null_type> cxx11_typelist; |
284 | #endif | |
285 | #ifdef _GLIBCXX_USE_CHAR8_T | |
286 | typedef char8_t a16; | |
287 | typedef node<_GLIBCXX_TYPELIST_CHAIN1(a16)> char8_typelist; | |
288 | #else | |
289 | typedef node<null_type> char8_typelist; | |
50ce8d3d | 290 | #endif |
59019b42 TH |
291 | typedef typename append<basic_typelist, cxx11_typelist>::type tl1; |
292 | typedef typename append<tl1, char8_typelist>::type type; | |
d466a7e2 BK |
293 | }; |
294 | ||
12bfa8bd PC |
295 | // A typelist of all standard integral types + the GNU 128-bit types. |
296 | struct integral_types_gnu | |
297 | { | |
298 | typedef bool a1; | |
299 | typedef char a2; | |
300 | typedef signed char a3; | |
301 | typedef unsigned char a4; | |
302 | typedef short a5; | |
303 | typedef unsigned short a6; | |
304 | typedef int a7; | |
305 | typedef unsigned int a8; | |
306 | typedef long a9; | |
307 | typedef unsigned long a10; | |
308 | typedef long long a11; | |
309 | typedef unsigned long long a12; | |
310 | typedef wchar_t a13; | |
59019b42 TH |
311 | typedef node<_GLIBCXX_TYPELIST_CHAIN13(a1, a2, a3, a4, a5, a6, a7, a8, a9, |
312 | a10, a11, a12, a13)> basic_typelist; | |
734f5023 | 313 | #if __cplusplus >= 201103L |
12bfa8bd PC |
314 | typedef char16_t a14; |
315 | typedef char32_t a15; | |
59019b42 TH |
316 | typedef node<_GLIBCXX_TYPELIST_CHAIN2(a14, a15)> cxx11_typelist; |
317 | #else | |
318 | typedef node<null_type> cxx11_typelist; | |
319 | #endif | |
320 | #ifdef _GLIBCXX_USE_CHAR8_T | |
321 | typedef char8_t a16; | |
322 | typedef node<_GLIBCXX_TYPELIST_CHAIN1(a16)> char8_typelist; | |
12bfa8bd | 323 | #else |
59019b42 TH |
324 | typedef node<null_type> char8_typelist; |
325 | #endif | |
12bfa8bd | 326 | # if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128) |
59019b42 TH |
327 | __extension__ typedef __int128 a17; |
328 | __extension__ typedef unsigned __int128 a18; | |
329 | typedef node<_GLIBCXX_TYPELIST_CHAIN2(a17, a18)> int128_typelist; | |
330 | #else | |
331 | typedef node<null_type> int128_typelist; | |
12bfa8bd | 332 | #endif |
59019b42 TH |
333 | typedef typename append<basic_typelist, cxx11_typelist>::type tl1; |
334 | typedef typename append<tl1, char8_typelist>::type tl2; | |
335 | typedef typename append<tl2, int128_typelist>::type type; | |
12bfa8bd PC |
336 | }; |
337 | ||
734f5023 | 338 | #if __cplusplus >= 201103L |
50ce8d3d BK |
339 | struct atomic_integrals_no_bool |
340 | { | |
341 | typedef std::atomic_char a2; | |
342 | typedef std::atomic_schar a3; | |
343 | typedef std::atomic_uchar a4; | |
344 | typedef std::atomic_short a5; | |
345 | typedef std::atomic_ushort a6; | |
346 | typedef std::atomic_int a7; | |
347 | typedef std::atomic_uint a8; | |
348 | typedef std::atomic_long a9; | |
349 | typedef std::atomic_ulong a10; | |
350 | typedef std::atomic_llong a11; | |
351 | typedef std::atomic_ullong a12; | |
352 | typedef std::atomic_wchar_t a13; | |
353 | typedef std::atomic_char16_t a14; | |
354 | typedef std::atomic_char32_t a15; | |
59019b42 TH |
355 | typedef node<_GLIBCXX_TYPELIST_CHAIN14(a2, a3, a4, a5, a6, a7, a8, a9, a10, |
356 | a11, a12, a13, a14, a15)> basic_typelist; | |
357 | #ifdef _GLIBCXX_USE_CHAR8_T | |
358 | typedef std::atomic_char8_t a16; | |
359 | typedef node<_GLIBCXX_TYPELIST_CHAIN1(a16)> char8_typelist; | |
360 | #else | |
361 | typedef node<null_type> char8_typelist; | |
362 | #endif | |
363 | typedef typename append<basic_typelist, char8_typelist>::type type; | |
50ce8d3d BK |
364 | }; |
365 | ||
366 | struct atomic_integrals | |
367 | { | |
368 | typedef std::atomic_bool a1; | |
369 | typedef std::atomic_char a2; | |
370 | typedef std::atomic_schar a3; | |
371 | typedef std::atomic_uchar a4; | |
372 | typedef std::atomic_short a5; | |
373 | typedef std::atomic_ushort a6; | |
374 | typedef std::atomic_int a7; | |
375 | typedef std::atomic_uint a8; | |
376 | typedef std::atomic_long a9; | |
377 | typedef std::atomic_ulong a10; | |
378 | typedef std::atomic_llong a11; | |
379 | typedef std::atomic_ullong a12; | |
380 | typedef std::atomic_wchar_t a13; | |
381 | typedef std::atomic_char16_t a14; | |
382 | typedef std::atomic_char32_t a15; | |
f92ab29f | 383 | typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9, |
59019b42 TH |
384 | a10, a11, a12, a13, a14, a15)> basic_typelist; |
385 | #ifdef _GLIBCXX_USE_CHAR8_T | |
386 | typedef std::atomic_char8_t a16; | |
387 | typedef node<_GLIBCXX_TYPELIST_CHAIN1(a16)> char8_typelist; | |
388 | #else | |
389 | typedef node<null_type> char8_typelist; | |
390 | #endif | |
391 | typedef typename append<basic_typelist, char8_typelist>::type type; | |
50ce8d3d BK |
392 | }; |
393 | ||
394 | ||
d466a7e2 BK |
395 | template<typename Tp> |
396 | struct atomics | |
397 | { | |
398 | typedef Tp value_type; | |
399 | typedef std::atomic<value_type> type; | |
400 | }; | |
401 | ||
402 | typedef transform<integral_types::type, atomics>::type atomics_tl; | |
403 | #endif | |
404 | ||
94a86be0 BK |
405 | template<typename Tp> |
406 | struct numeric_limits | |
407 | { | |
408 | typedef Tp value_type; | |
409 | typedef std::numeric_limits<value_type> type; | |
410 | }; | |
411 | ||
12bfa8bd | 412 | typedef transform<integral_types_gnu::type, numeric_limits>::type limits_tl; |
50ce8d3d BK |
413 | |
414 | struct has_increment_operators | |
415 | { | |
416 | template<typename _Tp> | |
f92ab29f | 417 | void |
50ce8d3d BK |
418 | operator()() |
419 | { | |
420 | struct _Concept | |
421 | { | |
422 | void __constraint() | |
423 | { | |
f92ab29f | 424 | _Tp a; |
50ce8d3d BK |
425 | ++a; // prefix |
426 | a++; // postfix | |
427 | a += a; | |
428 | } | |
429 | }; | |
430 | ||
431 | void (_Concept::*__x)() __attribute__((unused)) | |
432 | = &_Concept::__constraint; | |
433 | } | |
434 | }; | |
435 | ||
436 | struct has_decrement_operators | |
437 | { | |
438 | template<typename _Tp> | |
f92ab29f | 439 | void |
50ce8d3d BK |
440 | operator()() |
441 | { | |
442 | struct _Concept | |
443 | { | |
444 | void __constraint() | |
445 | { | |
f92ab29f | 446 | _Tp a; |
50ce8d3d BK |
447 | --a; // prefix |
448 | a--; // postfix | |
449 | a -= a; | |
450 | } | |
451 | }; | |
452 | ||
453 | void (_Concept::*__x)() __attribute__((unused)) | |
454 | = &_Concept::__constraint; | |
455 | } | |
456 | }; | |
457 | ||
734f5023 | 458 | #if __cplusplus >= 201103L |
94a86be0 BK |
459 | template<typename _Tp> |
460 | void | |
461 | constexpr_bitwise_operators() | |
462 | { | |
463 | constexpr _Tp a = _Tp(); | |
464 | constexpr _Tp b = _Tp(); | |
a9992f7f PC |
465 | constexpr _Tp c1 __attribute__((unused)) = a | b; |
466 | constexpr _Tp c2 __attribute__((unused)) = a & b; | |
467 | constexpr _Tp c3 __attribute__((unused)) = a ^ b; | |
468 | constexpr _Tp c4 __attribute__((unused)) = ~b; | |
94a86be0 BK |
469 | } |
470 | #endif | |
471 | ||
50ce8d3d BK |
472 | template<typename _Tp> |
473 | void | |
474 | bitwise_operators() | |
475 | { | |
c681c829 PC |
476 | _Tp a = _Tp(); |
477 | _Tp b = _Tp(); | |
50ce8d3d BK |
478 | a | b; |
479 | a & b; | |
480 | a ^ b; | |
481 | ~b; | |
482 | } | |
483 | ||
484 | template<typename _Tp> | |
485 | void | |
486 | bitwise_assignment_operators() | |
487 | { | |
432b6d95 JW |
488 | #if __cplusplus >= 201103L |
489 | _Tp a{}; | |
490 | _Tp b{}; | |
491 | #else | |
c681c829 PC |
492 | _Tp a = _Tp(); |
493 | _Tp b = _Tp(); | |
432b6d95 | 494 | #endif |
50ce8d3d BK |
495 | a |= b; // set |
496 | a &= ~b; // clear | |
497 | a ^= b; | |
498 | } | |
499 | ||
500 | // 17.3.2.1.2 - Bitmask types [lib.bitmask.types] | |
501 | // bitmask_operators | |
502 | template<typename _BitmTp> | |
503 | void | |
504 | bitmask_operators() | |
505 | { | |
506 | bitwise_operators<_BitmTp>(); | |
507 | bitwise_assignment_operators<_BitmTp>(); | |
508 | } | |
509 | ||
510 | struct has_bitwise_operators | |
511 | { | |
512 | template<typename _Tp> | |
f92ab29f | 513 | void |
50ce8d3d BK |
514 | operator()() |
515 | { | |
516 | struct _Concept | |
517 | { | |
518 | void __constraint() | |
519 | { | |
c681c829 PC |
520 | a |= b; // set |
521 | a &= ~b; // clear | |
522 | a ^= b; | |
50ce8d3d | 523 | } |
024615bf PC |
524 | _Tp a; |
525 | _Tp b; | |
50ce8d3d BK |
526 | }; |
527 | ||
528 | void (_Concept::*__x)() __attribute__((unused)) | |
529 | = &_Concept::__constraint; | |
530 | } | |
531 | }; | |
532 | ||
734f5023 | 533 | #if __cplusplus >= 201103L |
cde99631 BK |
534 | |
535 | struct constexpr_comparison_eq_ne | |
536 | { | |
537 | template<typename _Tp1, typename _Tp2 = _Tp1> | |
f92ab29f | 538 | void |
cde99631 BK |
539 | operator()() |
540 | { | |
541 | static_assert(_Tp1() == _Tp2(), "eq"); | |
542 | static_assert(!(_Tp1() != _Tp2()), "ne"); | |
543 | } | |
544 | }; | |
545 | ||
546 | struct constexpr_comparison_operators | |
547 | { | |
548 | template<typename _Tp> | |
f92ab29f | 549 | void |
cde99631 BK |
550 | operator()() |
551 | { | |
552 | static_assert(!(_Tp() < _Tp()), "less"); | |
553 | static_assert(_Tp() <= _Tp(), "leq"); | |
554 | static_assert(!(_Tp() > _Tp()), "more"); | |
555 | static_assert(_Tp() >= _Tp(), "meq"); | |
556 | static_assert(_Tp() == _Tp(), "eq"); | |
557 | static_assert(!(_Tp() != _Tp()), "ne"); | |
558 | } | |
559 | }; | |
560 | ||
5292c033 BK |
561 | struct has_trivial_cons_dtor |
562 | { | |
563 | template<typename _Tp> | |
f92ab29f | 564 | void |
5292c033 BK |
565 | operator()() |
566 | { | |
567 | struct _Concept | |
568 | { | |
569 | void __constraint() | |
570 | { | |
c66b93fe | 571 | typedef std::is_trivially_default_constructible<_Tp> ctor_p; |
5292c033 BK |
572 | static_assert(ctor_p::value, "default constructor not trivial"); |
573 | ||
6a9ecd34 | 574 | typedef std::is_trivially_destructible<_Tp> dtor_p; |
5292c033 BK |
575 | static_assert(dtor_p::value, "destructor not trivial"); |
576 | } | |
577 | }; | |
578 | ||
579 | void (_Concept::*__x)() __attribute__((unused)) | |
580 | = &_Concept::__constraint; | |
581 | } | |
582 | }; | |
583 | ||
e4379a93 JW |
584 | struct has_trivial_dtor |
585 | { | |
586 | template<typename _Tp> | |
587 | void | |
588 | operator()() | |
589 | { | |
590 | struct _Concept | |
591 | { | |
592 | void __constraint() | |
593 | { | |
594 | typedef std::is_trivially_destructible<_Tp> dtor_p; | |
595 | static_assert(dtor_p::value, "destructor not trivial"); | |
596 | } | |
597 | }; | |
598 | ||
599 | void (_Concept::*__x)() __attribute__((unused)) | |
600 | = &_Concept::__constraint; | |
601 | } | |
602 | }; | |
603 | ||
604 | // Generator to test standard layout | |
50ce8d3d BK |
605 | struct standard_layout |
606 | { | |
607 | template<typename _Tp> | |
f92ab29f | 608 | void |
50ce8d3d BK |
609 | operator()() |
610 | { | |
611 | struct _Concept | |
612 | { | |
613 | void __constraint() | |
614 | { | |
596cf1cc BK |
615 | typedef std::is_standard_layout<_Tp> standard_layout_p; |
616 | static_assert(standard_layout_p::value, "not standard_layout"); | |
50ce8d3d BK |
617 | } |
618 | }; | |
619 | ||
620 | void (_Concept::*__x)() __attribute__((unused)) | |
621 | = &_Concept::__constraint; | |
622 | } | |
623 | }; | |
624 | #endif | |
625 | ||
626 | // Generator to test base class | |
627 | struct has_required_base_class | |
628 | { | |
629 | template<typename _TBase, typename _TDerived> | |
f92ab29f | 630 | void |
50ce8d3d BK |
631 | operator()() |
632 | { | |
633 | struct _Concept | |
634 | { | |
635 | void __constraint() | |
636 | { | |
637 | const _TDerived& obj = __a; | |
638 | const _TBase* base __attribute__((unused)) = &obj; | |
639 | } | |
f92ab29f | 640 | |
50ce8d3d BK |
641 | _TDerived __a; |
642 | }; | |
643 | ||
644 | void (_Concept::*__x)() __attribute__((unused)) | |
645 | = &_Concept::__constraint; | |
646 | } | |
647 | }; | |
648 | ||
d466a7e2 BK |
649 | // Generator to test assignment operator. |
650 | struct assignable | |
651 | { | |
f0bbed44 | 652 | template<typename _Tp> |
f92ab29f | 653 | void |
d466a7e2 BK |
654 | operator()() |
655 | { | |
f0bbed44 PC |
656 | struct _Concept |
657 | { | |
658 | void __constraint() | |
659 | { __v1 = __v2; } | |
660 | ||
661 | _Tp __v1; | |
662 | _Tp __v2; | |
663 | }; | |
664 | ||
665 | void (_Concept::*__x)() __attribute__((unused)) | |
666 | = &_Concept::__constraint; | |
d466a7e2 BK |
667 | } |
668 | }; | |
669 | ||
670 | // Generator to test default constructor. | |
671 | struct default_constructible | |
672 | { | |
f0bbed44 | 673 | template<typename _Tp> |
f92ab29f | 674 | void |
d466a7e2 BK |
675 | operator()() |
676 | { | |
f0bbed44 PC |
677 | struct _Concept |
678 | { | |
679 | void __constraint() | |
a9992f7f | 680 | { _Tp __v __attribute__((unused)); } |
f0bbed44 PC |
681 | }; |
682 | ||
683 | void (_Concept::*__x)() __attribute__((unused)) | |
684 | = &_Concept::__constraint; | |
d466a7e2 BK |
685 | } |
686 | }; | |
687 | ||
688 | // Generator to test copy constructor. | |
689 | struct copy_constructible | |
690 | { | |
f0bbed44 | 691 | template<typename _Tp> |
f92ab29f | 692 | void |
d466a7e2 BK |
693 | operator()() |
694 | { | |
f0bbed44 PC |
695 | struct _Concept |
696 | { | |
697 | void __constraint() | |
698 | { _Tp __v2(__v1); } | |
699 | ||
700 | _Tp __v1; | |
701 | }; | |
702 | ||
703 | void (_Concept::*__x)() __attribute__((unused)) | |
704 | = &_Concept::__constraint; | |
d466a7e2 BK |
705 | } |
706 | }; | |
707 | ||
50ce8d3d BK |
708 | // Generator to test direct initialization, single value constructor. |
709 | struct single_value_constructible | |
d466a7e2 BK |
710 | { |
711 | template<typename _Ttype, typename _Tvalue> | |
f92ab29f | 712 | void |
d466a7e2 BK |
713 | operator()() |
714 | { | |
f0bbed44 PC |
715 | struct _Concept |
716 | { | |
717 | void __constraint() | |
718 | { _Ttype __v(__a); } | |
f92ab29f | 719 | |
f0bbed44 PC |
720 | _Tvalue __a; |
721 | }; | |
722 | ||
723 | void (_Concept::*__x)() __attribute__((unused)) | |
724 | = &_Concept::__constraint; | |
d466a7e2 BK |
725 | } |
726 | }; | |
fd1e1726 | 727 | |
734f5023 | 728 | #if __cplusplus >= 201103L |
dd9db6f8 JW |
729 | // Generator to test non-explicit default constructor. |
730 | struct implicitly_default_constructible | |
731 | { | |
732 | template<typename _Tp> | |
733 | void | |
734 | operator()() | |
735 | { | |
736 | struct _Concept | |
737 | { | |
738 | struct Aggregate { _Tp v; }; | |
739 | ||
740 | void __constraint() | |
741 | { Aggregate __v __attribute__((unused)) = { }; } | |
742 | }; | |
743 | ||
744 | void (_Concept::*__x)() __attribute__((unused)) | |
745 | = &_Concept::__constraint; | |
746 | } | |
747 | }; | |
748 | ||
94a86be0 BK |
749 | // Generator to test default constructor. |
750 | struct constexpr_default_constructible | |
751 | { | |
24b54628 | 752 | template<typename _Tp, bool _IsLitp = __is_literal_type(_Tp)> |
85db9dcc BK |
753 | struct _Concept; |
754 | ||
d326f2ee | 755 | // NB: _Tp must be a literal type. |
a1e1bc90 JW |
756 | // Have to have user-defined default ctor for this to work, |
757 | // or implicit default ctor must initialize all members. | |
85db9dcc BK |
758 | template<typename _Tp> |
759 | struct _Concept<_Tp, true> | |
760 | { | |
761 | void __constraint() | |
762 | { constexpr _Tp __obj; } | |
763 | }; | |
764 | ||
765 | // Non-literal type, declare local static and verify no | |
766 | // constructors generated for _Tp within the translation unit. | |
767 | template<typename _Tp> | |
768 | struct _Concept<_Tp, false> | |
769 | { | |
770 | void __constraint() | |
771 | { static _Tp __obj; } | |
772 | }; | |
773 | ||
94a86be0 | 774 | template<typename _Tp> |
f92ab29f | 775 | void |
94a86be0 BK |
776 | operator()() |
777 | { | |
85db9dcc BK |
778 | _Concept<_Tp> c; |
779 | c.__constraint(); | |
94a86be0 BK |
780 | } |
781 | }; | |
782 | ||
d326f2ee PC |
783 | // Generator to test defaulted default constructor. |
784 | struct constexpr_defaulted_default_constructible | |
785 | { | |
786 | template<typename _Tp> | |
787 | void | |
788 | operator()() | |
789 | { | |
790 | struct _Concept | |
791 | { | |
792 | void __constraint() | |
793 | { constexpr _Tp __v __attribute__((unused)) { }; } | |
794 | }; | |
795 | ||
796 | void (_Concept::*__x)() __attribute__((unused)) | |
797 | = &_Concept::__constraint; | |
798 | } | |
799 | }; | |
800 | ||
94a86be0 BK |
801 | struct constexpr_single_value_constructible |
802 | { | |
f92ab29f | 803 | template<typename _Ttesttype, typename _Tvaluetype, |
24b54628 | 804 | bool _IsLitp = __is_literal_type(_Ttesttype)> |
85db9dcc BK |
805 | struct _Concept; |
806 | ||
807 | // NB: _Tvaluetype and _Ttesttype must be literal types. | |
808 | // Additional constraint on _Tvaluetype needed. Either assume | |
809 | // user-defined default ctor as per | |
810 | // constexpr_default_constructible and provide no initializer, | |
811 | // provide an initializer, or assume empty-list init-able. Choose | |
812 | // the latter. | |
813 | template<typename _Ttesttype, typename _Tvaluetype> | |
814 | struct _Concept<_Ttesttype, _Tvaluetype, true> | |
94a86be0 | 815 | { |
85db9dcc | 816 | void __constraint() |
94a86be0 | 817 | { |
85db9dcc BK |
818 | constexpr _Tvaluetype __v { }; |
819 | constexpr _Ttesttype __obj(__v); | |
820 | } | |
821 | }; | |
94a86be0 | 822 | |
85db9dcc BK |
823 | template<typename _Ttesttype, typename _Tvaluetype> |
824 | struct _Concept<_Ttesttype, _Tvaluetype, false> | |
825 | { | |
826 | void __constraint() | |
f92ab29f | 827 | { |
85db9dcc BK |
828 | const _Tvaluetype __v { }; |
829 | static _Ttesttype __obj(__v); | |
830 | } | |
831 | }; | |
832 | ||
833 | template<typename _Ttesttype, typename _Tvaluetype> | |
834 | void | |
835 | operator()() | |
836 | { | |
837 | _Concept<_Ttesttype, _Tvaluetype> c; | |
94a86be0 BK |
838 | c.__constraint(); |
839 | } | |
840 | }; | |
841 | #endif | |
842 | ||
50ce8d3d | 843 | // Generator to test direct list initialization |
734f5023 | 844 | #if __cplusplus >= 201103L |
50ce8d3d BK |
845 | struct direct_list_initializable |
846 | { | |
847 | template<typename _Ttype, typename _Tvalue> | |
f92ab29f | 848 | void |
50ce8d3d BK |
849 | operator()() |
850 | { | |
851 | struct _Concept | |
852 | { | |
853 | void __constraint() | |
f92ab29f | 854 | { |
50ce8d3d BK |
855 | _Ttype __v1 { }; // default ctor |
856 | _Ttype __v2 { __a }; // single-argument ctor | |
857 | } | |
f92ab29f | 858 | |
50ce8d3d BK |
859 | _Tvalue __a; |
860 | }; | |
861 | ||
862 | void (_Concept::*__x)() __attribute__((unused)) | |
863 | = &_Concept::__constraint; | |
864 | } | |
865 | }; | |
866 | #endif | |
867 | ||
868 | // Generator to test copy list initialization, aggregate initialization | |
869 | struct copy_list_initializable | |
870 | { | |
871 | template<typename _Ttype, typename _Tvalue> | |
f92ab29f | 872 | void |
50ce8d3d BK |
873 | operator()() |
874 | { | |
875 | struct _Concept | |
876 | { | |
877 | void __constraint() | |
567d4027 | 878 | { _Ttype __v __attribute__((unused)) = {__a}; } |
f92ab29f | 879 | |
50ce8d3d BK |
880 | _Tvalue __a; |
881 | }; | |
882 | ||
883 | void (_Concept::*__x)() __attribute__((unused)) | |
884 | = &_Concept::__constraint; | |
885 | } | |
886 | }; | |
887 | ||
888 | // Generator to test integral conversion operator | |
889 | struct integral_convertable | |
890 | { | |
891 | template<typename _Ttype, typename _Tvalue> | |
f92ab29f | 892 | void |
50ce8d3d BK |
893 | operator()() |
894 | { | |
895 | struct _Concept | |
896 | { | |
897 | void __constraint() | |
898 | { | |
899 | _Tvalue __v0(0); | |
900 | _Tvalue __v1(1); | |
901 | _Ttype __a(__v1); | |
902 | __v0 = __a; | |
903 | ||
50ce8d3d BK |
904 | VERIFY( __v1 == __v0 ); |
905 | } | |
906 | }; | |
907 | ||
908 | void (_Concept::*__x)() __attribute__((unused)) | |
909 | = &_Concept::__constraint; | |
910 | } | |
911 | }; | |
912 | ||
f92ab29f | 913 | // Generator to test integral assignment operator |
50ce8d3d BK |
914 | struct integral_assignable |
915 | { | |
916 | template<typename _Ttype, typename _Tvalue> | |
f92ab29f | 917 | void |
50ce8d3d BK |
918 | operator()() |
919 | { | |
920 | struct _Concept | |
921 | { | |
922 | void __constraint() | |
923 | { | |
924 | _Tvalue __v0(0); | |
925 | _Tvalue __v1(1); | |
926 | _Ttype __a(__v0); | |
927 | __a = __v1; | |
928 | _Tvalue __vr = __a; | |
929 | ||
50ce8d3d BK |
930 | VERIFY( __v1 == __vr ); |
931 | } | |
932 | }; | |
933 | ||
934 | void (_Concept::*__x)() __attribute__((unused)) | |
935 | = &_Concept::__constraint; | |
936 | } | |
937 | }; | |
272827e4 NF |
938 | |
939 | #if __cplusplus >= 201103L | |
940 | // Generator to test lowering requirements for compare-and-exchange. | |
941 | template<std::memory_order _Torder> | |
942 | struct compare_exchange_order_lowering | |
943 | { | |
944 | template<typename _Tp> | |
945 | void | |
946 | operator()() | |
947 | { | |
948 | std::atomic<_Tp> __x; | |
949 | _Tp __expected = 0; | |
950 | __x.compare_exchange_strong(__expected, 1, _Torder); | |
951 | __x.compare_exchange_weak(__expected, 1, _Torder); | |
952 | } | |
953 | }; | |
954 | #endif | |
fd1e1726 | 955 | } // namespace __gnu_test |
fd1e1726 | 956 | #endif |