2 // Testing utilities for the tr1 testsuite.
4 // Copyright (C) 2004-2025 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 union IncompleteUnion
;
131 class IncompleteClass
;
135 ExplicitClass(double&);
136 explicit ExplicitClass(int&);
137 ExplicitClass(double&, int&, double&);
140 struct NothrowExplicitClass
142 NothrowExplicitClass(double&) throw();
143 explicit NothrowExplicitClass(int&) throw();
144 NothrowExplicitClass(double&, int&, double&) throw();
147 struct ThrowExplicitClass
149 ThrowExplicitClass(double&) THROW(int);
150 explicit ThrowExplicitClass(int&) THROW(int);
151 ThrowExplicitClass(double&, int&, double&) THROW(int);
154 struct ThrowDefaultClass
156 ThrowDefaultClass() THROW(int);
159 struct ThrowCopyConsClass
161 ThrowCopyConsClass(const ThrowCopyConsClass
&) THROW(int);
164 #if __cplusplus >= 201103L
165 struct ThrowMoveConsClass
167 ThrowMoveConsClass(ThrowMoveConsClass
&&) noexcept(false);
170 struct NoexceptExplicitClass
172 NoexceptExplicitClass(double&) noexcept(true);
173 explicit NoexceptExplicitClass(int&) noexcept(true);
174 NoexceptExplicitClass(double&, int&, double&) noexcept(true);
177 struct ExceptExplicitClass
179 ExceptExplicitClass(double&) noexcept(false);
180 explicit ExceptExplicitClass(int&) noexcept(false);
181 ExceptExplicitClass(double&, int&, double&) noexcept(false);
184 struct NoexceptDefaultClass
186 NoexceptDefaultClass() noexcept(true);
189 struct ExceptDefaultClass
191 ExceptDefaultClass() noexcept(false);
194 struct NoexceptCopyConsClass
196 NoexceptCopyConsClass(const NoexceptCopyConsClass
&) noexcept(true);
199 struct ExceptCopyConsClass
201 ExceptCopyConsClass(const ExceptCopyConsClass
&) noexcept(false);
204 struct NoexceptMoveConsClass
206 NoexceptMoveConsClass(NoexceptMoveConsClass
&&) noexcept(true);
207 NoexceptMoveConsClass
& operator=(NoexceptMoveConsClass
&&) = default;
210 struct ExceptMoveConsClass
212 ExceptMoveConsClass(ExceptMoveConsClass
&&) noexcept(false);
215 struct NoexceptCopyAssignClass
217 NoexceptCopyAssignClass
&
218 operator=(const NoexceptCopyAssignClass
&) noexcept(true);
221 struct ExceptCopyAssignClass
223 ExceptCopyAssignClass
&
224 operator=(const ExceptCopyAssignClass
&) noexcept(false);
227 struct NoexceptMoveAssignClass
229 NoexceptMoveAssignClass(NoexceptMoveAssignClass
&&) = default;
230 NoexceptMoveAssignClass
&
231 operator=(NoexceptMoveAssignClass
&&) noexcept(true);
234 struct ExceptMoveAssignClass
236 ExceptMoveAssignClass
&
237 operator=(ExceptMoveAssignClass
&&) noexcept(false);
240 struct DeletedCopyAssignClass
242 DeletedCopyAssignClass
&
243 operator=(const DeletedCopyAssignClass
&) = delete;
246 struct DeletedMoveAssignClass
248 DeletedMoveAssignClass
&
249 operator=(DeletedMoveAssignClass
&&) = delete;
252 struct NoexceptMoveConsNoexceptMoveAssignClass
254 NoexceptMoveConsNoexceptMoveAssignClass
255 (NoexceptMoveConsNoexceptMoveAssignClass
&&) noexcept(true);
257 NoexceptMoveConsNoexceptMoveAssignClass
&
258 operator=(NoexceptMoveConsNoexceptMoveAssignClass
&&) noexcept(true);
261 struct ExceptMoveConsNoexceptMoveAssignClass
263 ExceptMoveConsNoexceptMoveAssignClass
264 (ExceptMoveConsNoexceptMoveAssignClass
&&) noexcept(false);
266 ExceptMoveConsNoexceptMoveAssignClass
&
267 operator=(ExceptMoveConsNoexceptMoveAssignClass
&&) noexcept(true);
270 struct NoexceptMoveConsExceptMoveAssignClass
272 NoexceptMoveConsExceptMoveAssignClass
273 (NoexceptMoveConsExceptMoveAssignClass
&&) noexcept(true);
275 NoexceptMoveConsExceptMoveAssignClass
&
276 operator=(NoexceptMoveConsExceptMoveAssignClass
&&) noexcept(false);
279 struct ExceptMoveConsExceptMoveAssignClass
281 ExceptMoveConsExceptMoveAssignClass
282 (ExceptMoveConsExceptMoveAssignClass
&&) noexcept(false);
284 ExceptMoveConsExceptMoveAssignClass
&
285 operator=(ExceptMoveConsExceptMoveAssignClass
&&) noexcept(false);
289 struct NType
// neither trivial nor standard-layout
296 struct TType
// trivial but not standard-layout
303 struct SLType
// standard-layout but not trivial
310 struct PODType
// both trivial and standard-layout
316 #if __cplusplus >= 201103L
317 struct LType
// literal type
321 constexpr LType(int __i
) : _M_i(__i
) { }
324 struct LTypeDerived
: public LType
326 constexpr LTypeDerived(int __i
) : LType(__i
) { }
329 struct NLType
// not literal type
333 NLType() : _M_i(0) { }
335 constexpr NLType(int __i
) : _M_i(__i
) { }
337 NLType(const NLType
& __other
) : _M_i(__other
._M_i
) { }
339 ~NLType() { _M_i
= 0; }
343 int truncate_float(float x
) { return (int)x
; }
344 long truncate_double(double x
) { return (long)x
; }
346 struct do_truncate_float_t
348 do_truncate_float_t()
353 do_truncate_float_t(const do_truncate_float_t
&)
358 ~do_truncate_float_t()
363 int operator()(float x
) { return (int)x
; }
365 static int live_objects
;
368 int do_truncate_float_t::live_objects
= 0;
370 struct do_truncate_double_t
372 do_truncate_double_t()
377 do_truncate_double_t(const do_truncate_double_t
&)
382 ~do_truncate_double_t()
387 long operator()(double x
) { return (long)x
; }
389 static int live_objects
;
392 int do_truncate_double_t::live_objects
= 0;
398 int foo() { return 1; }
399 int foo_c() const { return 2; }
400 int foo_v() volatile { return 3; }
401 int foo_cv() const volatile { return 4; }
404 // For use in 8_c_compatibility.
405 template<typename R
, typename T
>
406 typename
__gnu_cxx::__enable_if
<std::__are_same
<R
, T
>::__value
,
411 #if __cplusplus >= 201103L
416 struct B
{ int i
; B(){} };
421 enum class SE
{ e1
};
422 enum class SE2
{ e2
};
425 enum class OpSE
: bool;
427 union U
{ int i
; Empty b
; };
431 virtual ~Abstract() = 0;
434 struct AbstractDelDtor
436 ~AbstractDelDtor() = delete;
437 virtual void foo() = 0;
451 operator To() = delete;
457 explicit operator To();
467 DelEllipsis(...) = delete;
485 DelnAny(T
&&...) = delete;
488 template<class... Args
>
501 DelCopy(const DelCopy
&) = delete;
507 DelDtor(const DelDtor
&) = default;
508 DelDtor(DelDtor
&&) = default;
517 Nontrivial(const Nontrivial
&);
518 Nontrivial
& operator=(const Nontrivial
&);
522 union NontrivialUnion
530 UnusualCopy(UnusualCopy
&);
556 ~TD1() noexcept(false);
585 ~Del2() noexcept
= delete;
590 ~Del3() noexcept(false) = delete;
615 enum class En
{ a
, b
, c
, d
};
616 enum En2
{ En2a
, En2b
, En2c
, En2d
};
619 enum class OpSE
: bool;
623 virtual ~Abstract1() = 0;
626 struct AbstractDelDtor
628 ~AbstractDelDtor() = delete;
629 virtual void foo() = 0;
634 virtual ~Abstract2() noexcept(false) = 0;
639 ~Abstract3() noexcept(false);
640 virtual void foo() noexcept
= 0;
646 Nontrivial(const Nontrivial
&);
647 Nontrivial
& operator=(const Nontrivial
&);
651 union NontrivialUnion
659 UnusualCopy(UnusualCopy
&);
669 DelEllipsis(...) = delete;
679 DelCopy(const DelCopy
&) = delete;
687 struct B
{ int i
; B(){} };
692 enum class SE
{ e1
};
693 enum class SE2
{ e2
};
696 enum class OpSE
: bool;
698 union U
{ int i
; Empty b
; };
713 void operator=(T
&&) = delete;
718 virtual ~Abstract() = 0;
721 struct AbstractDelDtor
723 ~AbstractDelDtor() = delete;
724 virtual void foo() = 0;
738 explicit operator To();
744 operator To() = delete;
750 explicit operator To() = delete;
760 DelEllipsis(...) = delete;
778 DelnAny(T
&&...) = delete;
781 template<class... Args
>
787 template<class... Args
>
790 DelFromArgs(Args
...) = delete;
800 DelCopy(const DelCopy
&) = delete;
806 DelDtor(const DelDtor
&) = default;
807 DelDtor(DelDtor
&&) = default;
816 Nontrivial(const Nontrivial
&);
817 Nontrivial
& operator=(const Nontrivial
&);
821 union NontrivialUnion
829 UnusualCopy(UnusualCopy
&);
841 void operator=(T
&&) = delete;
846 DelCopyAssign
& operator=(const DelCopyAssign
&) = delete;
847 DelCopyAssign
& operator=(DelCopyAssign
&&) = default;
853 MO
& operator=(MO
&&) = default;
857 struct CopyConsOnlyType
859 CopyConsOnlyType(int) { }
860 CopyConsOnlyType(CopyConsOnlyType
&&) = delete;
861 CopyConsOnlyType(const CopyConsOnlyType
&) = default;
862 CopyConsOnlyType
& operator=(const CopyConsOnlyType
&) = delete;
863 CopyConsOnlyType
& operator=(CopyConsOnlyType
&&) = delete;
866 struct MoveConsOnlyType
868 MoveConsOnlyType(int) { }
869 MoveConsOnlyType(const MoveConsOnlyType
&) = delete;
870 MoveConsOnlyType(MoveConsOnlyType
&&) = default;
871 MoveConsOnlyType
& operator=(const MoveConsOnlyType
&) = delete;
872 MoveConsOnlyType
& operator=(MoveConsOnlyType
&&) = delete;
876 } // namespace __gnu_test
878 #endif // _GLIBCXX_TESTSUITE_TR1_H