2 // Exception testing utils for the C++ library testsuite.
4 // Copyright (C) 2007-2013 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/>.
23 #include <testsuite_hooks.h>
25 #ifndef _TESTSUITE_API
26 #define _TESTSUITE_API 1
30 // Checks for virtual public derivation in exception classes.
32 // http://www.boost.org/more/error_handling.html
33 struct bad_non_virtual
: virtual public std::exception
{ };
35 template<typename Exception
, bool DefaultCons
>
36 struct diamond_derivation_base
;
38 template<typename Exception
>
39 struct diamond_derivation_base
<Exception
, true>
41 struct diamond_derivation_error
42 : bad_non_virtual
, Exception
44 diamond_derivation_error()
45 : bad_non_virtual(), Exception() { }
49 template<typename Exception
>
50 struct diamond_derivation_base
<Exception
, false>
52 struct diamond_derivation_error
53 : bad_non_virtual
, Exception
55 diamond_derivation_error()
56 : bad_non_virtual(), Exception("construct diamond") { }
60 template<typename Exception
, bool DefaultCons
>
61 struct diamond_derivation
62 : diamond_derivation_base
<Exception
, DefaultCons
>
64 typedef diamond_derivation_base
<Exception
, DefaultCons
> base_type
;
65 typedef typename
base_type::diamond_derivation_error error_type
;
67 // NB: In the libstdc++-v3 testsuite, all the standard exception
68 // classes (+ a couple of extensions) are checked: since they
69 // all derive *non* virtually from std::exception, the expected
70 // behavior is ambiguity.
73 bool test
__attribute__((unused
)) = true;
75 { throw error_type(); }
76 catch (std::exception
const&)
83 // Testing type requirements for template arguments.
84 struct NonDefaultConstructible
86 NonDefaultConstructible(int) { }
87 NonDefaultConstructible(const NonDefaultConstructible
&) { }
89 #if __cplusplus >= 201103L
91 NonDefaultConstructible
&
97 // See: 20.1.1 Template argument requirements.
99 operator==(const NonDefaultConstructible
&, const NonDefaultConstructible
&)
103 operator<(const NonDefaultConstructible
&, const NonDefaultConstructible
&)
106 // For 23 unordered_* requirements.
107 struct NonDefaultConstructible_hash
110 operator()(NonDefaultConstructible
) const
114 // For 26 numeric algorithms requirements, need addable,
115 // subtractable, multiplicable.
116 inline NonDefaultConstructible
117 operator+(const NonDefaultConstructible
& lhs
,
118 const NonDefaultConstructible
& rhs
)
119 { return NonDefaultConstructible(1); }
121 inline NonDefaultConstructible
122 operator-(const NonDefaultConstructible
& lhs
,
123 const NonDefaultConstructible
& rhs
)
124 { return NonDefaultConstructible(1); }
126 inline NonDefaultConstructible
127 operator*(const NonDefaultConstructible
& lhs
,
128 const NonDefaultConstructible
& rhs
)
129 { return NonDefaultConstructible(1); }
131 // Like unary_function, but takes no argument. (ie, void).
132 // Used for generator template parameter.
133 template<typename _Result
>
136 typedef _Result result_type
;
140 { return result_type(); }
144 struct void_function
<NonDefaultConstructible
>
146 typedef NonDefaultConstructible result_type
;
150 { return result_type(2); }
153 // For std::addressof, etc.
154 struct OverloadedAddressAux
{ };
156 struct OverloadedAddress
159 operator&() const { return OverloadedAddressAux(); }
163 operator<(const OverloadedAddress
&, const OverloadedAddress
&)
167 operator==(const OverloadedAddress
&, const OverloadedAddress
&)
170 struct OverloadedAddress_hash
173 operator()(const OverloadedAddress
&) const
177 #if __cplusplus >= 201103L
178 struct NonCopyConstructible
180 NonCopyConstructible() : num(-1) { }
182 NonCopyConstructible(NonCopyConstructible
&& other
)
186 NonCopyConstructible(const NonCopyConstructible
&) = delete;
188 operator int() { return num
; }