2018-03-08 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libstdc++-v3 / testsuite / util / testsuite_tr1.h
blobdbe99a9544e939e67336a470f047f8227f00661d
1 // -*- C++ -*-
2 // Testing utilities for the tr1 testsuite.
3 //
4 // Copyright (C) 2004-2018 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 _GLIBCXX_TESTSUITE_TR1_H
23 #define _GLIBCXX_TESTSUITE_TR1_H
25 #include <ext/type_traits.h>
26 #include <testsuite_hooks.h>
28 namespace __gnu_test
30 // For tr1/type_traits.
31 template<template<typename> class Category, typename Type>
32 #if __cplusplus >= 201103L
33 constexpr
34 #endif
35 bool
36 test_category(bool value)
38 return (Category<Type>::value == value
39 && Category<const Type>::value == value
40 && Category<volatile Type>::value == value
41 && Category<const volatile Type>::value == value
42 && Category<Type>::type::value == value
43 && Category<const Type>::type::value == value
44 && Category<volatile Type>::type::value == value
45 && Category<const volatile Type>::type::value == value);
48 // For testing tr1/type_traits/extent, which has a second template
49 // parameter.
50 template<template<typename, unsigned> class Property,
51 typename Type, unsigned Uint>
52 #if __cplusplus >= 201103L
53 constexpr
54 #endif
55 bool
56 test_property(typename Property<Type, Uint>::value_type value)
58 return (Property<Type, Uint>::value == value
59 && Property<Type, Uint>::type::value == value);
62 #if __cplusplus >= 201103L
63 template<template<typename...> class Property,
64 typename Type1, typename... Types>
65 constexpr bool
66 test_property(typename Property<Type1, Types...>::value_type value)
68 return (Property<Type1, Types...>::value == value
69 && Property<Type1, Types...>::type::value == value);
71 #else
72 template<template<typename> class Property, typename Type>
73 bool
74 test_property(typename Property<Type>::value_type value)
76 return (Property<Type>::value == value
77 && Property<Type>::type::value == value);
79 #endif
81 template<template<typename, typename> class Relationship,
82 typename Type1, typename Type2>
83 #if __cplusplus >= 201103L
84 constexpr
85 #endif
86 bool
87 test_relationship(bool value)
89 return (Relationship<Type1, Type2>::value == value
90 && Relationship<Type1, Type2>::type::value == value);
93 // Test types.
94 class ClassType { };
95 typedef const ClassType cClassType;
96 typedef volatile ClassType vClassType;
97 typedef const volatile ClassType cvClassType;
99 class DerivedType : public ClassType { };
101 #if __cplusplus >= 201103L
102 class FinalType final : public DerivedType { };
103 #endif
105 enum EnumType { e0 };
107 struct ConvType
108 { operator int() const; };
110 class AbstractClass
112 virtual void rotate(int) = 0;
115 class PolymorphicClass
117 virtual void rotate(int);
120 class DerivedPolymorphic : public PolymorphicClass { };
122 class VirtualDestructorClass
124 virtual ~VirtualDestructorClass();
127 union UnionType { };
129 class IncompleteClass;
131 struct ExplicitClass
133 ExplicitClass(double&);
134 explicit ExplicitClass(int&);
135 ExplicitClass(double&, int&, double&);
138 struct NothrowExplicitClass
140 NothrowExplicitClass(double&) throw();
141 explicit NothrowExplicitClass(int&) throw();
142 NothrowExplicitClass(double&, int&, double&) throw();
145 struct ThrowExplicitClass
147 ThrowExplicitClass(double&) THROW(int);
148 explicit ThrowExplicitClass(int&) THROW(int);
149 ThrowExplicitClass(double&, int&, double&) THROW(int);
152 struct ThrowDefaultClass
154 ThrowDefaultClass() THROW(int);
157 struct ThrowCopyConsClass
159 ThrowCopyConsClass(const ThrowCopyConsClass&) THROW(int);
162 #if __cplusplus >= 201103L
163 struct ThrowMoveConsClass
165 ThrowMoveConsClass(ThrowMoveConsClass&&) noexcept(false);
168 struct NoexceptExplicitClass
170 NoexceptExplicitClass(double&) noexcept(true);
171 explicit NoexceptExplicitClass(int&) noexcept(true);
172 NoexceptExplicitClass(double&, int&, double&) noexcept(true);
175 struct ExceptExplicitClass
177 ExceptExplicitClass(double&) noexcept(false);
178 explicit ExceptExplicitClass(int&) noexcept(false);
179 ExceptExplicitClass(double&, int&, double&) noexcept(false);
182 struct NoexceptDefaultClass
184 NoexceptDefaultClass() noexcept(true);
187 struct ExceptDefaultClass
189 ExceptDefaultClass() noexcept(false);
192 struct NoexceptCopyConsClass
194 NoexceptCopyConsClass(const NoexceptCopyConsClass&) noexcept(true);
197 struct ExceptCopyConsClass
199 ExceptCopyConsClass(const ExceptCopyConsClass&) noexcept(false);
202 struct NoexceptMoveConsClass
204 NoexceptMoveConsClass(NoexceptMoveConsClass&&) noexcept(true);
205 NoexceptMoveConsClass& operator=(NoexceptMoveConsClass&&) = default;
208 struct ExceptMoveConsClass
210 ExceptMoveConsClass(ExceptMoveConsClass&&) noexcept(false);
213 struct NoexceptCopyAssignClass
215 NoexceptCopyAssignClass&
216 operator=(const NoexceptCopyAssignClass&) noexcept(true);
219 struct ExceptCopyAssignClass
221 ExceptCopyAssignClass&
222 operator=(const ExceptCopyAssignClass&) noexcept(false);
225 struct NoexceptMoveAssignClass
227 NoexceptMoveAssignClass(NoexceptMoveAssignClass&&) = default;
228 NoexceptMoveAssignClass&
229 operator=(NoexceptMoveAssignClass&&) noexcept(true);
232 struct ExceptMoveAssignClass
234 ExceptMoveAssignClass&
235 operator=(ExceptMoveAssignClass&&) noexcept(false);
238 struct DeletedCopyAssignClass
240 DeletedCopyAssignClass&
241 operator=(const DeletedCopyAssignClass&) = delete;
244 struct DeletedMoveAssignClass
246 DeletedMoveAssignClass&
247 operator=(DeletedMoveAssignClass&&) = delete;
250 struct NoexceptMoveConsNoexceptMoveAssignClass
252 NoexceptMoveConsNoexceptMoveAssignClass
253 (NoexceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
255 NoexceptMoveConsNoexceptMoveAssignClass&
256 operator=(NoexceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
259 struct ExceptMoveConsNoexceptMoveAssignClass
261 ExceptMoveConsNoexceptMoveAssignClass
262 (ExceptMoveConsNoexceptMoveAssignClass&&) noexcept(false);
264 ExceptMoveConsNoexceptMoveAssignClass&
265 operator=(ExceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
268 struct NoexceptMoveConsExceptMoveAssignClass
270 NoexceptMoveConsExceptMoveAssignClass
271 (NoexceptMoveConsExceptMoveAssignClass&&) noexcept(true);
273 NoexceptMoveConsExceptMoveAssignClass&
274 operator=(NoexceptMoveConsExceptMoveAssignClass&&) noexcept(false);
277 struct ExceptMoveConsExceptMoveAssignClass
279 ExceptMoveConsExceptMoveAssignClass
280 (ExceptMoveConsExceptMoveAssignClass&&) noexcept(false);
282 ExceptMoveConsExceptMoveAssignClass&
283 operator=(ExceptMoveConsExceptMoveAssignClass&&) noexcept(false);
285 #endif
287 struct NType // neither trivial nor standard-layout
289 int i;
290 int j;
291 virtual ~NType();
294 struct TType // trivial but not standard-layout
296 int i;
297 private:
298 int j;
301 struct SLType // standard-layout but not trivial
303 int i;
304 int j;
305 ~SLType();
308 struct PODType // both trivial and standard-layout
310 int i;
311 int j;
314 #if __cplusplus >= 201103L
315 struct LType // literal type
317 int _M_i;
319 constexpr LType(int __i) : _M_i(__i) { }
322 struct LTypeDerived : public LType
324 constexpr LTypeDerived(int __i) : LType(__i) { }
327 struct NLType // not literal type
329 int _M_i;
331 NLType() : _M_i(0) { }
333 constexpr NLType(int __i) : _M_i(__i) { }
335 NLType(const NLType& __other) : _M_i(__other._M_i) { }
337 ~NLType() { _M_i = 0; }
339 #endif
341 int truncate_float(float x) { return (int)x; }
342 long truncate_double(double x) { return (long)x; }
344 struct do_truncate_float_t
346 do_truncate_float_t()
348 ++live_objects;
351 do_truncate_float_t(const do_truncate_float_t&)
353 ++live_objects;
356 ~do_truncate_float_t()
358 --live_objects;
361 int operator()(float x) { return (int)x; }
363 static int live_objects;
366 int do_truncate_float_t::live_objects = 0;
368 struct do_truncate_double_t
370 do_truncate_double_t()
372 ++live_objects;
375 do_truncate_double_t(const do_truncate_double_t&)
377 ++live_objects;
380 ~do_truncate_double_t()
382 --live_objects;
385 long operator()(double x) { return (long)x; }
387 static int live_objects;
390 int do_truncate_double_t::live_objects = 0;
392 struct X
394 int bar;
396 int foo() { return 1; }
397 int foo_c() const { return 2; }
398 int foo_v() volatile { return 3; }
399 int foo_cv() const volatile { return 4; }
402 // For use in 8_c_compatibility.
403 template<typename R, typename T>
404 typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value,
405 bool>::__type
406 check_ret_type(T)
407 { return true; }
409 #if __cplusplus >= 201103L
410 namespace construct
412 struct Empty {};
414 struct B { int i; B(){} };
415 struct D : B {};
417 enum E { ee1 };
418 enum E2 { ee2 };
419 enum class SE { e1 };
420 enum class SE2 { e2 };
422 enum OpE : int;
423 enum class OpSE : bool;
425 union U { int i; Empty b; };
427 struct Abstract
429 virtual ~Abstract() = 0;
432 struct AbstractDelDtor
434 ~AbstractDelDtor() = delete;
435 virtual void foo() = 0;
438 struct Ukn;
440 template<class To>
441 struct ImplicitTo
443 operator To();
446 template<class To>
447 struct DelImplicitTo
449 operator To() = delete;
452 template<class To>
453 struct ExplicitTo
455 explicit operator To();
458 struct Ellipsis
460 Ellipsis(...){}
463 struct DelEllipsis
465 DelEllipsis(...) = delete;
468 struct Any
470 template<class T>
471 Any(T&&){}
474 struct nAny
476 template<class... T>
477 nAny(T&&...){}
480 struct DelnAny
482 template<class... T>
483 DelnAny(T&&...) = delete;
486 template<class... Args>
487 struct FromArgs
489 FromArgs(Args...);
492 struct DelDef
494 DelDef() = delete;
497 struct DelCopy
499 DelCopy(const DelCopy&) = delete;
502 struct DelDtor
504 DelDtor() = default;
505 DelDtor(const DelDtor&) = default;
506 DelDtor(DelDtor&&) = default;
507 DelDtor(int);
508 DelDtor(int, B, U);
509 ~DelDtor() = delete;
512 struct Nontrivial
514 Nontrivial();
515 Nontrivial(const Nontrivial&);
516 Nontrivial& operator=(const Nontrivial&);
517 ~Nontrivial();
520 union NontrivialUnion
522 int i;
523 Nontrivial n;
526 struct UnusualCopy
528 UnusualCopy(UnusualCopy&);
532 namespace destruct
534 struct E
537 struct NTD1
539 ~NTD1() = default;
542 struct NTD2
544 ~NTD2();
547 struct NTD3
549 ~NTD3() throw();
552 struct TD1
554 ~TD1() noexcept(false);
557 struct TD2
559 ~TD2() THROW(int);
562 struct Aggr
564 int i;
565 bool b;
566 E e;
569 struct Aggr2
571 int i;
572 bool b;
573 TD1 r;
576 struct Del
578 ~Del() = delete;
581 struct Del2
583 ~Del2() noexcept = delete;
586 struct Del3
588 ~Del3() noexcept(false) = delete;
591 struct Der : Aggr
594 struct Der2 : Aggr2
597 union U1
599 int i;
600 double d;
601 void* p;
602 TD1* pt;
605 union Ut
607 int i;
608 double d;
609 void* p;
610 TD1 pt;
613 enum class En { a, b, c, d };
614 enum En2 { En2a, En2b, En2c, En2d };
616 enum OpE : int;
617 enum class OpSE : bool;
619 struct Abstract1
621 virtual ~Abstract1() = 0;
624 struct AbstractDelDtor
626 ~AbstractDelDtor() = delete;
627 virtual void foo() = 0;
630 struct Abstract2
632 virtual ~Abstract2() noexcept(false) = 0;
635 struct Abstract3
637 ~Abstract3() noexcept(false);
638 virtual void foo() noexcept = 0;
641 struct Nontrivial
643 Nontrivial();
644 Nontrivial(const Nontrivial&);
645 Nontrivial& operator=(const Nontrivial&);
646 ~Nontrivial();
649 union NontrivialUnion
651 int i;
652 Nontrivial n;
655 struct UnusualCopy
657 UnusualCopy(UnusualCopy&);
660 struct Ellipsis
662 Ellipsis(...){}
665 struct DelEllipsis
667 DelEllipsis(...) = delete;
670 struct DelDef
672 DelDef() = delete;
675 struct DelCopy
677 DelCopy(const DelCopy&) = delete;
681 namespace assign
683 struct Empty {};
685 struct B { int i; B(){} };
686 struct D : B {};
688 enum E { ee1 };
689 enum E2 { ee2 };
690 enum class SE { e1 };
691 enum class SE2 { e2 };
693 enum OpE : int;
694 enum class OpSE : bool;
696 union U { int i; Empty b; };
698 union UAssignAll
700 bool b;
701 char c;
702 template<class T>
703 void operator=(T&&);
706 union UDelAssignAll
708 bool b;
709 char c;
710 template<class T>
711 void operator=(T&&) = delete;
714 struct Abstract
716 virtual ~Abstract() = 0;
719 struct AbstractDelDtor
721 ~AbstractDelDtor() = delete;
722 virtual void foo() = 0;
725 struct Ukn;
727 template<class To>
728 struct ImplicitTo
730 operator To();
733 template<class To>
734 struct ExplicitTo
736 explicit operator To();
739 template<class To>
740 struct DelImplicitTo
742 operator To() = delete;
745 template<class To>
746 struct DelExplicitTo
748 explicit operator To() = delete;
751 struct Ellipsis
753 Ellipsis(...){}
756 struct DelEllipsis
758 DelEllipsis(...) = delete;
761 struct Any
763 template<class T>
764 Any(T&&){}
767 struct nAny
769 template<class... T>
770 nAny(T&&...){}
773 struct DelnAny
775 template<class... T>
776 DelnAny(T&&...) = delete;
779 template<class... Args>
780 struct FromArgs
782 FromArgs(Args...);
785 template<class... Args>
786 struct DelFromArgs
788 DelFromArgs(Args...) = delete;
791 struct DelDef
793 DelDef() = delete;
796 struct DelCopy
798 DelCopy(const DelCopy&) = delete;
801 struct DelDtor
803 DelDtor() = default;
804 DelDtor(const DelDtor&) = default;
805 DelDtor(DelDtor&&) = default;
806 DelDtor(int);
807 DelDtor(int, B, U);
808 ~DelDtor() = delete;
811 struct Nontrivial
813 Nontrivial();
814 Nontrivial(const Nontrivial&);
815 Nontrivial& operator=(const Nontrivial&);
816 ~Nontrivial();
819 union NontrivialUnion
821 int i;
822 Nontrivial n;
825 struct UnusualCopy
827 UnusualCopy(UnusualCopy&);
830 struct AnyAssign
832 template<class T>
833 void operator=(T&&);
836 struct DelAnyAssign
838 template<class T>
839 void operator=(T&&) = delete;
842 struct DelCopyAssign
844 DelCopyAssign& operator=(const DelCopyAssign&) = delete;
845 DelCopyAssign& operator=(DelCopyAssign&&) = default;
848 struct MO
850 MO(MO&&) = default;
851 MO& operator=(MO&&) = default;
855 struct CopyConsOnlyType
857 CopyConsOnlyType(int) { }
858 CopyConsOnlyType(CopyConsOnlyType&&) = delete;
859 CopyConsOnlyType(const CopyConsOnlyType&) = default;
860 CopyConsOnlyType& operator=(const CopyConsOnlyType&) = delete;
861 CopyConsOnlyType& operator=(CopyConsOnlyType&&) = delete;
864 struct MoveConsOnlyType
866 MoveConsOnlyType(int) { }
867 MoveConsOnlyType(const MoveConsOnlyType&) = delete;
868 MoveConsOnlyType(MoveConsOnlyType&&) = default;
869 MoveConsOnlyType& operator=(const MoveConsOnlyType&) = delete;
870 MoveConsOnlyType& operator=(MoveConsOnlyType&&) = delete;
872 #endif
874 } // namespace __gnu_test
876 #endif // _GLIBCXX_TESTSUITE_TR1_H