2 // Testing utilities for the tr1 testsuite.
4 // Copyright (C) 2004-2018 Free Software Foundation, Inc.
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)
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>
30 // For tr1/type_traits.
31 template<template<typename
> class Category
, typename Type
>
32 #if __cplusplus >= 201103L
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
50 template<template<typename
, unsigned> class Property
,
51 typename Type
, unsigned Uint
>
52 #if __cplusplus >= 201103L
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
>
66 test_property(typename Property
<Type1
, Types
...>::value_type value
)
68 return (Property
<Type1
, Types
...>::value
== value
69 && Property
<Type1
, Types
...>::type::value
== value
);
72 template<template<typename
> class Property
, typename Type
>
74 test_property(typename Property
<Type
>::value_type value
)
76 return (Property
<Type
>::value
== value
77 && Property
<Type
>::type::value
== value
);
81 template<template<typename
, typename
> class Relationship
,
82 typename Type1
, typename Type2
>
83 #if __cplusplus >= 201103L
87 test_relationship(bool value
)
89 return (Relationship
<Type1
, Type2
>::value
== value
90 && Relationship
<Type1
, Type2
>::type::value
== value
);
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
{ };
105 enum EnumType
{ e0
};
108 { operator int() const; };
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();
129 class IncompleteClass
;
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);
287 struct NType
// neither trivial nor standard-layout
294 struct TType
// trivial but not standard-layout
301 struct SLType
// standard-layout but not trivial
308 struct PODType
// both trivial and standard-layout
314 #if __cplusplus >= 201103L
315 struct LType
// literal type
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
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; }
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()
351 do_truncate_float_t(const do_truncate_float_t
&)
356 ~do_truncate_float_t()
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()
375 do_truncate_double_t(const do_truncate_double_t
&)
380 ~do_truncate_double_t()
385 long operator()(double x
) { return (long)x
; }
387 static int live_objects
;
390 int do_truncate_double_t::live_objects
= 0;
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
,
409 #if __cplusplus >= 201103L
414 struct B
{ int i
; B(){} };
419 enum class SE
{ e1
};
420 enum class SE2
{ e2
};
423 enum class OpSE
: bool;
425 union U
{ int i
; Empty b
; };
429 virtual ~Abstract() = 0;
432 struct AbstractDelDtor
434 ~AbstractDelDtor() = delete;
435 virtual void foo() = 0;
449 operator To() = delete;
455 explicit operator To();
465 DelEllipsis(...) = delete;
483 DelnAny(T
&&...) = delete;
486 template<class... Args
>
499 DelCopy(const DelCopy
&) = delete;
505 DelDtor(const DelDtor
&) = default;
506 DelDtor(DelDtor
&&) = default;
515 Nontrivial(const Nontrivial
&);
516 Nontrivial
& operator=(const Nontrivial
&);
520 union NontrivialUnion
528 UnusualCopy(UnusualCopy
&);
554 ~TD1() noexcept(false);
583 ~Del2() noexcept
= delete;
588 ~Del3() noexcept(false) = delete;
613 enum class En
{ a
, b
, c
, d
};
614 enum En2
{ En2a
, En2b
, En2c
, En2d
};
617 enum class OpSE
: bool;
621 virtual ~Abstract1() = 0;
624 struct AbstractDelDtor
626 ~AbstractDelDtor() = delete;
627 virtual void foo() = 0;
632 virtual ~Abstract2() noexcept(false) = 0;
637 ~Abstract3() noexcept(false);
638 virtual void foo() noexcept
= 0;
644 Nontrivial(const Nontrivial
&);
645 Nontrivial
& operator=(const Nontrivial
&);
649 union NontrivialUnion
657 UnusualCopy(UnusualCopy
&);
667 DelEllipsis(...) = delete;
677 DelCopy(const DelCopy
&) = delete;
685 struct B
{ int i
; B(){} };
690 enum class SE
{ e1
};
691 enum class SE2
{ e2
};
694 enum class OpSE
: bool;
696 union U
{ int i
; Empty b
; };
711 void operator=(T
&&) = delete;
716 virtual ~Abstract() = 0;
719 struct AbstractDelDtor
721 ~AbstractDelDtor() = delete;
722 virtual void foo() = 0;
736 explicit operator To();
742 operator To() = delete;
748 explicit operator To() = delete;
758 DelEllipsis(...) = delete;
776 DelnAny(T
&&...) = delete;
779 template<class... Args
>
785 template<class... Args
>
788 DelFromArgs(Args
...) = delete;
798 DelCopy(const DelCopy
&) = delete;
804 DelDtor(const DelDtor
&) = default;
805 DelDtor(DelDtor
&&) = default;
814 Nontrivial(const Nontrivial
&);
815 Nontrivial
& operator=(const Nontrivial
&);
819 union NontrivialUnion
827 UnusualCopy(UnusualCopy
&);
839 void operator=(T
&&) = delete;
844 DelCopyAssign
& operator=(const DelCopyAssign
&) = delete;
845 DelCopyAssign
& operator=(DelCopyAssign
&&) = 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;
874 } // namespace __gnu_test
876 #endif // _GLIBCXX_TESTSUITE_TR1_H