2 // Exception testing utils for the C++ library testsuite.
4 // Copyright (C) 2007, 2008, 2009, 2010 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/>.
24 #include <testsuite_hooks.h>
26 #ifndef _TESTSUITE_API
27 #define _TESTSUITE_API 1
31 // Checks for virtual public derivation in exception classes.
33 // http://www.boost.org/more/error_handling.html
34 struct bad_non_virtual
: virtual public std::exception
{ };
36 template<typename Exception
, bool DefaultCons
>
37 struct diamond_derivation_base
;
39 template<typename Exception
>
40 struct diamond_derivation_base
<Exception
, true>
42 struct diamond_derivation_error
43 : bad_non_virtual
, Exception
45 diamond_derivation_error()
46 : bad_non_virtual(), Exception() { }
50 template<typename Exception
>
51 struct diamond_derivation_base
<Exception
, false>
53 struct diamond_derivation_error
54 : bad_non_virtual
, Exception
56 diamond_derivation_error()
57 : bad_non_virtual(), Exception("construct diamond") { }
61 template<typename Exception
, bool DefaultCons
>
62 struct diamond_derivation
63 : diamond_derivation_base
<Exception
, DefaultCons
>
65 typedef diamond_derivation_base
<Exception
, DefaultCons
> base_type
;
66 typedef typename
base_type::diamond_derivation_error error_type
;
68 // NB: In the libstdc++-v3 testsuite, all the standard exception
69 // classes (+ a couple of extensions) are checked: since they
70 // all derive *non* virtually from std::exception, the expected
71 // behavior is ambiguity.
74 bool test
__attribute__((unused
)) = true;
76 { throw error_type(); }
77 catch (std::exception
const&)
84 // Testing type requirements for template arguments.
85 struct NonDefaultConstructible
87 NonDefaultConstructible(int) { }
88 NonDefaultConstructible(const NonDefaultConstructible
&) { }
90 #ifdef __GXX_EXPERIMENTAL_CXX0X__
92 NonDefaultConstructible
&
98 // See: 20.1.1 Template argument requirements.
100 operator==(const NonDefaultConstructible
&, const NonDefaultConstructible
&)
104 operator<(const NonDefaultConstructible
&, const NonDefaultConstructible
&)
107 // For 23 unordered_* requirements.
108 struct NonDefaultConstructible_hash
111 operator()(NonDefaultConstructible
) const
115 // For 26 numeric algorithms requirements, need addable,
116 // subtractable, multiplicable.
117 inline NonDefaultConstructible
118 operator+(const NonDefaultConstructible
& lhs
,
119 const NonDefaultConstructible
& rhs
)
120 { return NonDefaultConstructible(1); }
122 inline NonDefaultConstructible
123 operator-(const NonDefaultConstructible
& lhs
,
124 const NonDefaultConstructible
& rhs
)
125 { return NonDefaultConstructible(1); }
127 inline NonDefaultConstructible
128 operator*(const NonDefaultConstructible
& lhs
,
129 const NonDefaultConstructible
& rhs
)
130 { return NonDefaultConstructible(1); }
132 // Like unary_function, but takes no argument. (ie, void).
133 // Used for generator template parameter.
134 template<typename _Result
>
137 typedef _Result result_type
;
141 { return result_type(); }
145 struct void_function
<NonDefaultConstructible
>
147 typedef NonDefaultConstructible result_type
;
151 { return result_type(2); }
154 // For std::addressof, etc.
155 struct OverloadedAddressAux
{ };
157 struct OverloadedAddress
160 operator&() const { return OverloadedAddressAux(); }
164 operator<(const OverloadedAddress
&, const OverloadedAddress
&)
168 operator==(const OverloadedAddress
&, const OverloadedAddress
&)
171 struct OverloadedAddress_hash
174 operator()(const OverloadedAddress
&) const