Debian Codegraph @

libstdc++-v3/testsuite/util/testsuite_common_types.h

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