2 // Testing utilities for the tr1 testsuite.
4 // Copyright (C) 2004-2014 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>
29 // For tr1/type_traits.
30 template<template<typename
> class Category
, typename Type
>
31 #if __cplusplus >= 201103L
35 test_category(bool value
)
37 return (Category
<Type
>::value
== value
38 && Category
<const Type
>::value
== value
39 && Category
<volatile Type
>::value
== value
40 && Category
<const volatile Type
>::value
== value
41 && Category
<Type
>::type::value
== value
42 && Category
<const Type
>::type::value
== value
43 && Category
<volatile Type
>::type::value
== value
44 && Category
<const volatile Type
>::type::value
== value
);
47 template<template<typename
> class Property
, typename Type
>
48 #if __cplusplus >= 201103L
52 test_property(typename Property
<Type
>::value_type value
)
54 return (Property
<Type
>::value
== value
55 && Property
<Type
>::type::value
== value
);
58 // For testing tr1/type_traits/extent, which has a second template
60 template<template<typename
, unsigned> class Property
,
61 typename Type
, unsigned Uint
>
62 #if __cplusplus >= 201103L
66 test_property(typename Property
<Type
, Uint
>::value_type value
)
68 return (Property
<Type
, Uint
>::value
== value
69 && Property
<Type
, Uint
>::type::value
== value
);
72 #if __cplusplus >= 201103L
73 template<template<typename
...> class Property
,
74 typename Type1
, typename
... Types
>
76 test_property(typename Property
<Type1
, Types
...>::value_type value
)
78 return (Property
<Type1
, Types
...>::value
== value
79 && Property
<Type1
, Types
...>::type::value
== value
);
83 template<template<typename
, typename
> class Relationship
,
84 typename Type1
, typename Type2
>
85 #if __cplusplus >= 201103L
89 test_relationship(bool value
)
91 return (Relationship
<Type1
, Type2
>::value
== value
92 && Relationship
<Type1
, Type2
>::type::value
== value
);
97 typedef const ClassType cClassType
;
98 typedef volatile ClassType vClassType
;
99 typedef const volatile ClassType cvClassType
;
101 class DerivedType
: public ClassType
{ };
103 enum EnumType
{ e0
};
106 { operator int() const; };
110 virtual void rotate(int) = 0;
113 class PolymorphicClass
115 virtual void rotate(int);
118 class DerivedPolymorphic
: public PolymorphicClass
{ };
120 class VirtualDestructorClass
122 virtual ~VirtualDestructorClass();
127 class IncompleteClass
;
131 ExplicitClass(double&);
132 explicit ExplicitClass(int&);
133 ExplicitClass(double&, int&, double&);
136 struct NothrowExplicitClass
138 NothrowExplicitClass(double&) throw();
139 explicit NothrowExplicitClass(int&) throw();
140 NothrowExplicitClass(double&, int&, double&) throw();
143 struct ThrowExplicitClass
145 ThrowExplicitClass(double&) throw(int);
146 explicit ThrowExplicitClass(int&) throw(int);
147 ThrowExplicitClass(double&, int&, double&) throw(int);
150 struct ThrowDefaultClass
152 ThrowDefaultClass() throw(int);
155 struct ThrowCopyConsClass
157 ThrowCopyConsClass(const ThrowCopyConsClass
&) throw(int);
160 #if __cplusplus >= 201103L
161 struct ThrowMoveConsClass
163 ThrowMoveConsClass(ThrowMoveConsClass
&&) throw(int);
166 struct NoexceptExplicitClass
168 NoexceptExplicitClass(double&) noexcept(true);
169 explicit NoexceptExplicitClass(int&) noexcept(true);
170 NoexceptExplicitClass(double&, int&, double&) noexcept(true);
173 struct ExceptExplicitClass
175 ExceptExplicitClass(double&) noexcept(false);
176 explicit ExceptExplicitClass(int&) noexcept(false);
177 ExceptExplicitClass(double&, int&, double&) noexcept(false);
180 struct NoexceptDefaultClass
182 NoexceptDefaultClass() noexcept(true);
185 struct ExceptDefaultClass
187 ExceptDefaultClass() noexcept(false);
190 struct NoexceptCopyConsClass
192 NoexceptCopyConsClass(const NoexceptCopyConsClass
&) noexcept(true);
195 struct ExceptCopyConsClass
197 ExceptCopyConsClass(const ExceptCopyConsClass
&) noexcept(false);
200 struct NoexceptMoveConsClass
202 NoexceptMoveConsClass(NoexceptMoveConsClass
&&) noexcept(true);
203 NoexceptMoveConsClass
& operator=(NoexceptMoveConsClass
&&) = default;
206 struct ExceptMoveConsClass
208 ExceptMoveConsClass(ExceptMoveConsClass
&&) noexcept(false);
211 struct NoexceptCopyAssignClass
213 NoexceptCopyAssignClass
&
214 operator=(const NoexceptCopyAssignClass
&) noexcept(true);
217 struct ExceptCopyAssignClass
219 ExceptCopyAssignClass
&
220 operator=(const ExceptCopyAssignClass
&) noexcept(false);
223 struct NoexceptMoveAssignClass
225 NoexceptMoveAssignClass(NoexceptMoveAssignClass
&&) = default;
226 NoexceptMoveAssignClass
&
227 operator=(NoexceptMoveAssignClass
&&) noexcept(true);
230 struct ExceptMoveAssignClass
232 ExceptMoveAssignClass
&
233 operator=(ExceptMoveAssignClass
&&) noexcept(false);
236 struct DeletedCopyAssignClass
238 DeletedCopyAssignClass
&
239 operator=(const DeletedCopyAssignClass
&) = delete;
242 struct DeletedMoveAssignClass
244 DeletedMoveAssignClass
&
245 operator=(DeletedMoveAssignClass
&&) = delete;
248 struct NoexceptMoveConsNoexceptMoveAssignClass
250 NoexceptMoveConsNoexceptMoveAssignClass
251 (NoexceptMoveConsNoexceptMoveAssignClass
&&) noexcept(true);
253 NoexceptMoveConsNoexceptMoveAssignClass
&
254 operator=(NoexceptMoveConsNoexceptMoveAssignClass
&&) noexcept(true);
257 struct ExceptMoveConsNoexceptMoveAssignClass
259 ExceptMoveConsNoexceptMoveAssignClass
260 (ExceptMoveConsNoexceptMoveAssignClass
&&) noexcept(false);
262 ExceptMoveConsNoexceptMoveAssignClass
&
263 operator=(ExceptMoveConsNoexceptMoveAssignClass
&&) noexcept(true);
266 struct NoexceptMoveConsExceptMoveAssignClass
268 NoexceptMoveConsExceptMoveAssignClass
269 (NoexceptMoveConsExceptMoveAssignClass
&&) noexcept(true);
271 NoexceptMoveConsExceptMoveAssignClass
&
272 operator=(NoexceptMoveConsExceptMoveAssignClass
&&) noexcept(false);
275 struct ExceptMoveConsExceptMoveAssignClass
277 ExceptMoveConsExceptMoveAssignClass
278 (ExceptMoveConsExceptMoveAssignClass
&&) noexcept(false);
280 ExceptMoveConsExceptMoveAssignClass
&
281 operator=(ExceptMoveConsExceptMoveAssignClass
&&) noexcept(false);
285 struct NType
// neither trivial nor standard-layout
292 struct TType
// trivial but not standard-layout
299 struct SLType
// standard-layout but not trivial
306 struct PODType
// both trivial and standard-layout
312 #if __cplusplus >= 201103L
313 struct LType
// literal type
317 constexpr LType(int __i
) : _M_i(__i
) { }
320 struct LTypeDerived
: public LType
322 constexpr LTypeDerived(int __i
) : LType(__i
) { }
325 struct NLType
// not literal type
329 NLType() : _M_i(0) { }
331 constexpr NLType(int __i
) : _M_i(__i
) { }
333 NLType(const NLType
& __other
) : _M_i(__other
._M_i
) { }
335 ~NLType() { _M_i
= 0; }
339 int truncate_float(float x
) { return (int)x
; }
340 long truncate_double(double x
) { return (long)x
; }
342 struct do_truncate_float_t
344 do_truncate_float_t()
349 do_truncate_float_t(const do_truncate_float_t
&)
354 ~do_truncate_float_t()
359 int operator()(float x
) { return (int)x
; }
361 static int live_objects
;
364 int do_truncate_float_t::live_objects
= 0;
366 struct do_truncate_double_t
368 do_truncate_double_t()
373 do_truncate_double_t(const do_truncate_double_t
&)
378 ~do_truncate_double_t()
383 long operator()(double x
) { return (long)x
; }
385 static int live_objects
;
388 int do_truncate_double_t::live_objects
= 0;
394 int foo() { return 1; }
395 int foo_c() const { return 2; }
396 int foo_v() volatile { return 3; }
397 int foo_cv() const volatile { return 4; }
400 // For use in 8_c_compatibility.
401 template<typename R
, typename T
>
402 typename
__gnu_cxx::__enable_if
<std::__are_same
<R
, T
>::__value
,
407 #if __cplusplus >= 201103L
412 struct B
{ int i
; B(){} };
417 enum class SE
{ e1
};
418 enum class SE2
{ e2
};
421 enum class OpSE
: bool;
423 union U
{ int i
; Empty b
; };
427 virtual ~Abstract() = 0;
430 struct AbstractDelDtor
432 ~AbstractDelDtor() = delete;
433 virtual void foo() = 0;
447 operator To() = delete;
453 explicit operator To();
463 DelEllipsis(...) = delete;
481 DelnAny(T
&&...) = delete;
484 template<class... Args
>
497 DelCopy(const DelCopy
&) = delete;
503 DelDtor(const DelDtor
&) = default;
504 DelDtor(DelDtor
&&) = default;
513 Nontrivial(const Nontrivial
&);
514 Nontrivial
& operator=(const Nontrivial
&);
518 union NontrivialUnion
526 UnusualCopy(UnusualCopy
&);
552 ~TD1() noexcept(false);
581 ~Del2() noexcept
= delete;
586 ~Del3() noexcept(false) = delete;
611 enum class En
{ a
, b
, c
, d
};
612 enum En2
{ En2a
, En2b
, En2c
, En2d
};
615 enum class OpSE
: bool;
619 virtual ~Abstract1() = 0;
622 struct AbstractDelDtor
624 ~AbstractDelDtor() = delete;
625 virtual void foo() = 0;
630 virtual ~Abstract2() noexcept(false) = 0;
635 ~Abstract3() noexcept(false);
636 virtual void foo() noexcept
= 0;
642 Nontrivial(const Nontrivial
&);
643 Nontrivial
& operator=(const Nontrivial
&);
647 union NontrivialUnion
655 UnusualCopy(UnusualCopy
&);
665 DelEllipsis(...) = delete;
675 DelCopy(const DelCopy
&) = delete;
683 struct B
{ int i
; B(){} };
688 enum class SE
{ e1
};
689 enum class SE2
{ e2
};
692 enum class OpSE
: bool;
694 union U
{ int i
; Empty b
; };
709 void operator=(T
&&) = delete;
714 virtual ~Abstract() = 0;
717 struct AbstractDelDtor
719 ~AbstractDelDtor() = delete;
720 virtual void foo() = 0;
734 explicit operator To();
740 operator To() = delete;
746 explicit operator To() = delete;
756 DelEllipsis(...) = delete;
774 DelnAny(T
&&...) = delete;
777 template<class... Args
>
783 template<class... Args
>
786 DelFromArgs(Args
...) = delete;
796 DelCopy(const DelCopy
&) = delete;
802 DelDtor(const DelDtor
&) = default;
803 DelDtor(DelDtor
&&) = default;
812 Nontrivial(const Nontrivial
&);
813 Nontrivial
& operator=(const Nontrivial
&);
817 union NontrivialUnion
825 UnusualCopy(UnusualCopy
&);
837 void operator=(T
&&) = delete;
842 DelCopyAssign
& operator=(const DelCopyAssign
&) = delete;
843 DelCopyAssign
& operator=(DelCopyAssign
&&) = default;
849 MO
& operator=(MO
&&) = default;
853 struct CopyConsOnlyType
855 CopyConsOnlyType(int) { }
856 CopyConsOnlyType(CopyConsOnlyType
&&) = delete;
857 CopyConsOnlyType(const CopyConsOnlyType
&) = default;
858 CopyConsOnlyType
& operator=(const CopyConsOnlyType
&) = delete;
859 CopyConsOnlyType
& operator=(CopyConsOnlyType
&&) = delete;
862 struct MoveConsOnlyType
864 MoveConsOnlyType(int) { }
865 MoveConsOnlyType(const MoveConsOnlyType
&) = delete;
866 MoveConsOnlyType(MoveConsOnlyType
&&) = default;
867 MoveConsOnlyType
& operator=(const MoveConsOnlyType
&) = delete;
868 MoveConsOnlyType
& operator=(MoveConsOnlyType
&&) = delete;
872 } // namespace __gnu_test
874 #endif // _GLIBCXX_TESTSUITE_TR1_H