* config/sparc/sparc.c (sparc_option_override): Set MASK_FSMULD flag
[official-gcc.git] / libstdc++-v3 / testsuite / util / testsuite_common_types.h
blobd2efe3af556f9d1b19c7858cfe9c5464f1e0b7b4
1 // -*- C++ -*-
2 // typelist for the C++ library testsuite.
3 //
4 // Copyright (C) 2005-2017 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.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
22 #ifndef _TESTSUITE_COMMON_TYPES_H
23 #define _TESTSUITE_COMMON_TYPES_H 1
25 #include <ext/typelist.h>
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>
33 #include <algorithm>
35 #include <vector>
36 #include <list>
37 #include <deque>
38 #include <string>
39 #include <limits>
41 #include <map>
42 #include <set>
43 #include <tr1/functional>
44 #include <tr1/unordered_map>
45 #include <tr1/unordered_set>
47 #if __cplusplus >= 201103L
48 #include <atomic>
49 #include <type_traits>
50 #endif
52 namespace __gnu_test
54 using __gnu_cxx::typelist::node;
55 using __gnu_cxx::typelist::transform;
56 using __gnu_cxx::typelist::append;
58 // All the allocators to test.
59 template<typename Tp, bool Thread>
60 struct allocator_policies
62 typedef Tp value_type;
63 typedef __gnu_cxx::new_allocator<Tp> a1;
64 typedef __gnu_cxx::malloc_allocator<Tp> a2;
65 typedef __gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, Thread> pool_policy;
66 typedef __gnu_cxx::__mt_alloc<Tp, pool_policy> a3;
67 typedef __gnu_cxx::bitmap_allocator<Tp> a4;
68 typedef __gnu_cxx::__pool_alloc<Tp> a5;
69 typedef node<_GLIBCXX_TYPELIST_CHAIN5(a1, a2, a3, a4, a5)> type;
72 // Typelists for vector, string, list, deque.
73 // XXX should just use template templates
74 template<typename Tp, bool Thread>
75 struct vectors
77 typedef Tp value_type;
79 template<typename Tl>
80 struct vector_shell
82 typedef Tl allocator_type;
83 typedef std::vector<value_type, allocator_type> type;
86 typedef allocator_policies<value_type, Thread> allocator_types;
87 typedef typename allocator_types::type allocator_typelist;
88 typedef typename transform<allocator_typelist, vector_shell>::type type;
91 template<typename Tp, bool Thread>
92 struct lists
94 typedef Tp value_type;
96 template<typename Tl>
97 struct list_shell
99 typedef Tl allocator_type;
100 typedef std::list<value_type, allocator_type> type;
103 typedef allocator_policies<value_type, Thread> allocator_types;
104 typedef typename allocator_types::type allocator_typelist;
105 typedef typename transform<allocator_typelist, list_shell>::type type;
108 template<typename Tp, bool Thread>
109 struct deques
111 typedef Tp value_type;
113 template<typename Tl>
114 struct deque_shell
116 typedef Tl allocator_type;
117 typedef std::deque<value_type, allocator_type> type;
120 typedef allocator_policies<value_type, Thread> allocator_types;
121 typedef typename allocator_types::type allocator_typelist;
122 typedef typename transform<allocator_typelist, deque_shell>::type type;
125 template<typename Tp, bool Thread>
126 struct strings
128 typedef Tp value_type;
130 template<typename Tl>
131 struct string_shell
133 typedef Tl allocator_type;
134 typedef std::char_traits<value_type> traits_type;
135 typedef std::basic_string<value_type, traits_type, allocator_type> type;
138 typedef allocator_policies<value_type, Thread> allocator_types;
139 typedef typename allocator_types::type allocator_typelist;
140 typedef typename transform<allocator_typelist, string_shell>::type type;
143 // A typelist of vector, list, deque, and string all instantiated
144 // with each of the allocator policies.
145 template<typename Tp, bool Thread>
146 struct sequence_containers
148 typedef Tp value_type;
150 typedef typename vectors<value_type, Thread>::type vector_typelist;
151 typedef typename lists<value_type, Thread>::type list_typelist;
152 typedef typename deques<value_type, Thread>::type deque_typelist;
153 typedef typename strings<value_type, Thread>::type string_typelist;
155 typedef typename append<vector_typelist, list_typelist>::type a1;
156 typedef typename append<deque_typelist, string_typelist>::type a2;
157 typedef typename append<a1, a2>::type type;
160 // Typelists for map, set, unordered_set, unordered_map.
161 template<typename Tp, bool Thread>
162 struct maps
164 typedef Tp value_type;
165 typedef Tp key_type;
166 typedef std::pair<const key_type, value_type> pair_type;
167 typedef std::less<key_type> compare_function;
169 template<typename Tl>
170 struct container
172 typedef Tl allocator_type;
173 typedef std::map<key_type, value_type, compare_function, allocator_type> type;
176 typedef allocator_policies<pair_type, Thread> allocator_types;
177 typedef typename allocator_types::type allocator_typelist;
178 typedef typename transform<allocator_typelist, container>::type type;
181 template<typename Tp, bool Thread>
182 struct unordered_maps
184 typedef Tp value_type;
185 typedef Tp key_type;
186 typedef std::pair<const key_type, value_type> pair_type;
187 typedef std::tr1::hash<key_type> hash_function;
188 typedef std::equal_to<key_type> equality_function;
190 template<typename Tl>
191 struct container
193 typedef Tl allocator_type;
194 typedef std::tr1::unordered_map<key_type, value_type, hash_function, equality_function, allocator_type> type;
197 typedef allocator_policies<pair_type, Thread> allocator_types;
198 typedef typename allocator_types::type allocator_typelist;
199 typedef typename transform<allocator_typelist, container>::type type;
202 template<typename Tp, bool Thread>
203 struct sets
205 typedef Tp value_type;
206 typedef Tp key_type;
207 typedef std::less<key_type> compare_function;
209 template<typename Tl>
210 struct container
212 typedef Tl allocator_type;
213 typedef std::set<key_type, compare_function, allocator_type> type;
216 typedef allocator_policies<key_type, Thread> allocator_types;
217 typedef typename allocator_types::type allocator_typelist;
218 typedef typename transform<allocator_typelist, container>::type type;
221 template<typename Tp, bool Thread>
222 struct unordered_sets
224 typedef Tp value_type;
225 typedef Tp key_type;
226 typedef std::tr1::hash<key_type> hash_function;
227 typedef std::equal_to<key_type> equality_function;
229 template<typename Tl>
230 struct container
232 typedef Tl allocator_type;
233 typedef std::tr1::unordered_set<key_type, hash_function, equality_function, allocator_type> type;
236 typedef allocator_policies<key_type, Thread> allocator_types;
237 typedef typename allocator_types::type allocator_typelist;
238 typedef typename transform<allocator_typelist, container>::type type;
242 // A typelist of all associated container types, with each of the
243 // allocator policies.
244 template<typename Tp, bool Thread>
245 struct associative_containers
247 typedef Tp value_type;
249 typedef typename maps<value_type, Thread>::type map_typelist;
250 typedef typename sets<value_type, Thread>::type set_typelist;
251 typedef typename unordered_maps<value_type, Thread>::type unordered_map_typelist;
252 typedef typename unordered_sets<value_type, Thread>::type unordered_set_typelist;
254 typedef typename append<map_typelist, unordered_map_typelist>::type a1;
255 typedef typename append<set_typelist, unordered_set_typelist>::type a2;
256 typedef typename append<a1, a2>::type type;
259 // A typelist of all standard integral types.
260 struct integral_types
262 typedef bool a1;
263 typedef char a2;
264 typedef signed char a3;
265 typedef unsigned char a4;
266 typedef short a5;
267 typedef unsigned short a6;
268 typedef int a7;
269 typedef unsigned int a8;
270 typedef long a9;
271 typedef unsigned long a10;
272 typedef long long a11;
273 typedef unsigned long long a12;
274 typedef wchar_t a13;
275 #if __cplusplus >= 201103L
276 typedef char16_t a14;
277 typedef char32_t a15;
279 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
280 a10, a11, a12, a13, a14, a15)> type;
281 #else
282 typedef node<_GLIBCXX_TYPELIST_CHAIN13(a1, a2, a3, a4, a5, a6, a7, a8, a9,
283 a10, a11, a12, a13)> type;
284 #endif
287 // A typelist of all standard integral types + the GNU 128-bit types.
288 struct integral_types_gnu
290 typedef bool a1;
291 typedef char a2;
292 typedef signed char a3;
293 typedef unsigned char a4;
294 typedef short a5;
295 typedef unsigned short a6;
296 typedef int a7;
297 typedef unsigned int a8;
298 typedef long a9;
299 typedef unsigned long a10;
300 typedef long long a11;
301 typedef unsigned long long a12;
302 typedef wchar_t a13;
303 #if __cplusplus >= 201103L
304 typedef char16_t a14;
305 typedef char32_t a15;
306 # if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
307 __extension__ typedef __int128 a16;
308 __extension__ typedef unsigned __int128 a17;
310 typedef node<_GLIBCXX_TYPELIST_CHAIN17(a1, a2, a3, a4, a5, a6, a7, a8, a9,
311 a10, a11, a12, a13, a14, a15,
312 a16, a17)> type;
313 # else
314 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
315 a10, a11, a12, a13, a14, a15)> type;
316 # endif
317 #else
318 # if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
319 __extension__ typedef __int128 a14;
320 __extension__ typedef unsigned __int128 a15;
322 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
323 a10, a11, a12, a13, a14, a15)> type;
324 # else
325 typedef node<_GLIBCXX_TYPELIST_CHAIN13(a1, a2, a3, a4, a5, a6, a7, a8, a9,
326 a10, a11, a12, a13)> type;
327 # endif
328 #endif
331 #if __cplusplus >= 201103L
332 struct atomic_integrals_no_bool
334 typedef std::atomic_char a2;
335 typedef std::atomic_schar a3;
336 typedef std::atomic_uchar a4;
337 typedef std::atomic_short a5;
338 typedef std::atomic_ushort a6;
339 typedef std::atomic_int a7;
340 typedef std::atomic_uint a8;
341 typedef std::atomic_long a9;
342 typedef std::atomic_ulong a10;
343 typedef std::atomic_llong a11;
344 typedef std::atomic_ullong a12;
345 typedef std::atomic_wchar_t a13;
346 typedef std::atomic_char16_t a14;
347 typedef std::atomic_char32_t a15;
349 typedef node<_GLIBCXX_TYPELIST_CHAIN14(a2, a3, a4, a5, a6, a7, a8, a9,
350 a10, a11, a12, a13, a14, a15)> type;
353 struct atomic_integrals
355 typedef std::atomic_bool a1;
356 typedef std::atomic_char a2;
357 typedef std::atomic_schar a3;
358 typedef std::atomic_uchar a4;
359 typedef std::atomic_short a5;
360 typedef std::atomic_ushort a6;
361 typedef std::atomic_int a7;
362 typedef std::atomic_uint a8;
363 typedef std::atomic_long a9;
364 typedef std::atomic_ulong a10;
365 typedef std::atomic_llong a11;
366 typedef std::atomic_ullong a12;
367 typedef std::atomic_wchar_t a13;
368 typedef std::atomic_char16_t a14;
369 typedef std::atomic_char32_t a15;
371 typedef node<_GLIBCXX_TYPELIST_CHAIN15(a1, a2, a3, a4, a5, a6, a7, a8, a9,
372 a10, a11, a12, a13, a14, a15)> type;
376 template<typename Tp>
377 struct atomics
379 typedef Tp value_type;
380 typedef std::atomic<value_type> type;
383 typedef transform<integral_types::type, atomics>::type atomics_tl;
384 #endif
386 template<typename Tp>
387 struct numeric_limits
389 typedef Tp value_type;
390 typedef std::numeric_limits<value_type> type;
393 typedef transform<integral_types_gnu::type, numeric_limits>::type limits_tl;
395 struct has_increment_operators
397 template<typename _Tp>
398 void
399 operator()()
401 struct _Concept
403 void __constraint()
405 _Tp a;
406 ++a; // prefix
407 a++; // postfix
408 a += a;
412 void (_Concept::*__x)() __attribute__((unused))
413 = &_Concept::__constraint;
417 struct has_decrement_operators
419 template<typename _Tp>
420 void
421 operator()()
423 struct _Concept
425 void __constraint()
427 _Tp a;
428 --a; // prefix
429 a--; // postfix
430 a -= a;
434 void (_Concept::*__x)() __attribute__((unused))
435 = &_Concept::__constraint;
439 #if __cplusplus >= 201103L
440 template<typename _Tp>
441 void
442 constexpr_bitwise_operators()
444 constexpr _Tp a = _Tp();
445 constexpr _Tp b = _Tp();
446 constexpr _Tp c1 __attribute__((unused)) = a | b;
447 constexpr _Tp c2 __attribute__((unused)) = a & b;
448 constexpr _Tp c3 __attribute__((unused)) = a ^ b;
449 constexpr _Tp c4 __attribute__((unused)) = ~b;
451 #endif
453 template<typename _Tp>
454 void
455 bitwise_operators()
457 _Tp a = _Tp();
458 _Tp b = _Tp();
459 a | b;
460 a & b;
461 a ^ b;
465 template<typename _Tp>
466 void
467 bitwise_assignment_operators()
469 #if __cplusplus >= 201103L
470 _Tp a{};
471 _Tp b{};
472 #else
473 _Tp a = _Tp();
474 _Tp b = _Tp();
475 #endif
476 a |= b; // set
477 a &= ~b; // clear
478 a ^= b;
481 // 17.3.2.1.2 - Bitmask types [lib.bitmask.types]
482 // bitmask_operators
483 template<typename _BitmTp>
484 void
485 bitmask_operators()
487 bitwise_operators<_BitmTp>();
488 bitwise_assignment_operators<_BitmTp>();
491 struct has_bitwise_operators
493 template<typename _Tp>
494 void
495 operator()()
497 struct _Concept
499 void __constraint()
501 a |= b; // set
502 a &= ~b; // clear
503 a ^= b;
505 _Tp a;
506 _Tp b;
509 void (_Concept::*__x)() __attribute__((unused))
510 = &_Concept::__constraint;
514 #if __cplusplus >= 201103L
516 struct constexpr_comparison_eq_ne
518 template<typename _Tp1, typename _Tp2 = _Tp1>
519 void
520 operator()()
522 static_assert(_Tp1() == _Tp2(), "eq");
523 static_assert(!(_Tp1() != _Tp2()), "ne");
527 struct constexpr_comparison_operators
529 template<typename _Tp>
530 void
531 operator()()
533 static_assert(!(_Tp() < _Tp()), "less");
534 static_assert(_Tp() <= _Tp(), "leq");
535 static_assert(!(_Tp() > _Tp()), "more");
536 static_assert(_Tp() >= _Tp(), "meq");
537 static_assert(_Tp() == _Tp(), "eq");
538 static_assert(!(_Tp() != _Tp()), "ne");
542 // Generator to test standard layout
543 struct has_trivial_cons_dtor
545 template<typename _Tp>
546 void
547 operator()()
549 struct _Concept
551 void __constraint()
553 typedef std::is_trivially_default_constructible<_Tp> ctor_p;
554 static_assert(ctor_p::value, "default constructor not trivial");
556 typedef std::is_trivially_destructible<_Tp> dtor_p;
557 static_assert(dtor_p::value, "destructor not trivial");
561 void (_Concept::*__x)() __attribute__((unused))
562 = &_Concept::__constraint;
566 struct standard_layout
568 template<typename _Tp>
569 void
570 operator()()
572 struct _Concept
574 void __constraint()
576 typedef std::is_standard_layout<_Tp> standard_layout_p;
577 static_assert(standard_layout_p::value, "not standard_layout");
581 void (_Concept::*__x)() __attribute__((unused))
582 = &_Concept::__constraint;
585 #endif
587 // Generator to test base class
588 struct has_required_base_class
590 template<typename _TBase, typename _TDerived>
591 void
592 operator()()
594 struct _Concept
596 void __constraint()
598 const _TDerived& obj = __a;
599 const _TBase* base __attribute__((unused)) = &obj;
602 _TDerived __a;
605 void (_Concept::*__x)() __attribute__((unused))
606 = &_Concept::__constraint;
610 // Generator to test assignment operator.
611 struct assignable
613 template<typename _Tp>
614 void
615 operator()()
617 struct _Concept
619 void __constraint()
620 { __v1 = __v2; }
622 _Tp __v1;
623 _Tp __v2;
626 void (_Concept::*__x)() __attribute__((unused))
627 = &_Concept::__constraint;
631 // Generator to test default constructor.
632 struct default_constructible
634 template<typename _Tp>
635 void
636 operator()()
638 struct _Concept
640 void __constraint()
641 { _Tp __v __attribute__((unused)); }
644 void (_Concept::*__x)() __attribute__((unused))
645 = &_Concept::__constraint;
649 // Generator to test copy constructor.
650 struct copy_constructible
652 template<typename _Tp>
653 void
654 operator()()
656 struct _Concept
658 void __constraint()
659 { _Tp __v2(__v1); }
661 _Tp __v1;
664 void (_Concept::*__x)() __attribute__((unused))
665 = &_Concept::__constraint;
669 // Generator to test direct initialization, single value constructor.
670 struct single_value_constructible
672 template<typename _Ttype, typename _Tvalue>
673 void
674 operator()()
676 struct _Concept
678 void __constraint()
679 { _Ttype __v(__a); }
681 _Tvalue __a;
684 void (_Concept::*__x)() __attribute__((unused))
685 = &_Concept::__constraint;
689 #if __cplusplus >= 201103L
690 // Generator to test default constructor.
691 struct constexpr_default_constructible
693 template<typename _Tp, bool _IsLitp = std::is_literal_type<_Tp>::value>
694 struct _Concept;
696 // NB: _Tp must be a literal type.
697 // Have to have user-defined default ctor for this to work,
698 // or implicit default ctor must initialize all members.
699 template<typename _Tp>
700 struct _Concept<_Tp, true>
702 void __constraint()
703 { constexpr _Tp __obj; }
706 // Non-literal type, declare local static and verify no
707 // constructors generated for _Tp within the translation unit.
708 template<typename _Tp>
709 struct _Concept<_Tp, false>
711 void __constraint()
712 { static _Tp __obj; }
715 template<typename _Tp>
716 void
717 operator()()
719 _Concept<_Tp> c;
720 c.__constraint();
724 // Generator to test defaulted default constructor.
725 struct constexpr_defaulted_default_constructible
727 template<typename _Tp>
728 void
729 operator()()
731 struct _Concept
733 void __constraint()
734 { constexpr _Tp __v __attribute__((unused)) { }; }
737 void (_Concept::*__x)() __attribute__((unused))
738 = &_Concept::__constraint;
742 struct constexpr_single_value_constructible
744 template<typename _Ttesttype, typename _Tvaluetype,
745 bool _IsLitp = std::is_literal_type<_Ttesttype>::value>
746 struct _Concept;
748 // NB: _Tvaluetype and _Ttesttype must be literal types.
749 // Additional constraint on _Tvaluetype needed. Either assume
750 // user-defined default ctor as per
751 // constexpr_default_constructible and provide no initializer,
752 // provide an initializer, or assume empty-list init-able. Choose
753 // the latter.
754 template<typename _Ttesttype, typename _Tvaluetype>
755 struct _Concept<_Ttesttype, _Tvaluetype, true>
757 void __constraint()
759 constexpr _Tvaluetype __v { };
760 constexpr _Ttesttype __obj(__v);
764 template<typename _Ttesttype, typename _Tvaluetype>
765 struct _Concept<_Ttesttype, _Tvaluetype, false>
767 void __constraint()
769 const _Tvaluetype __v { };
770 static _Ttesttype __obj(__v);
774 template<typename _Ttesttype, typename _Tvaluetype>
775 void
776 operator()()
778 _Concept<_Ttesttype, _Tvaluetype> c;
779 c.__constraint();
782 #endif
784 // Generator to test direct list initialization
785 #if __cplusplus >= 201103L
786 struct direct_list_initializable
788 template<typename _Ttype, typename _Tvalue>
789 void
790 operator()()
792 struct _Concept
794 void __constraint()
796 _Ttype __v1 { }; // default ctor
797 _Ttype __v2 { __a }; // single-argument ctor
800 _Tvalue __a;
803 void (_Concept::*__x)() __attribute__((unused))
804 = &_Concept::__constraint;
807 #endif
809 // Generator to test copy list initialization, aggregate initialization
810 struct copy_list_initializable
812 template<typename _Ttype, typename _Tvalue>
813 void
814 operator()()
816 struct _Concept
818 void __constraint()
819 { _Ttype __v __attribute__((unused)) = {__a}; }
821 _Tvalue __a;
824 void (_Concept::*__x)() __attribute__((unused))
825 = &_Concept::__constraint;
829 // Generator to test integral conversion operator
830 struct integral_convertable
832 template<typename _Ttype, typename _Tvalue>
833 void
834 operator()()
836 struct _Concept
838 void __constraint()
840 _Tvalue __v0(0);
841 _Tvalue __v1(1);
842 _Ttype __a(__v1);
843 __v0 = __a;
845 VERIFY( __v1 == __v0 );
849 void (_Concept::*__x)() __attribute__((unused))
850 = &_Concept::__constraint;
854 // Generator to test integral assignment operator
855 struct integral_assignable
857 template<typename _Ttype, typename _Tvalue>
858 void
859 operator()()
861 struct _Concept
863 void __constraint()
865 _Tvalue __v0(0);
866 _Tvalue __v1(1);
867 _Ttype __a(__v0);
868 __a = __v1;
869 _Tvalue __vr = __a;
871 VERIFY( __v1 == __vr );
875 void (_Concept::*__x)() __attribute__((unused))
876 = &_Concept::__constraint;
880 #if __cplusplus >= 201103L
881 // Generator to test lowering requirements for compare-and-exchange.
882 template<std::memory_order _Torder>
883 struct compare_exchange_order_lowering
885 template<typename _Tp>
886 void
887 operator()()
889 std::atomic<_Tp> __x;
890 _Tp __expected = 0;
891 __x.compare_exchange_strong(__expected, 1, _Torder);
892 __x.compare_exchange_weak(__expected, 1, _Torder);
895 #endif
896 } // namespace __gnu_test
897 #endif