]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/util/testsuite_api.h
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / testsuite_api.h
1 // -*- C++ -*-
2 // Exception testing utils for the C++ library testsuite.
3 //
4 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
5 //
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)
10 // any later version.
11 //
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.
16 //
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/>.
20 //
21
22 #include <exception>
23 #include <testsuite_hooks.h>
24
25 #ifndef _TESTSUITE_API
26 #define _TESTSUITE_API 1
27
28 namespace __gnu_test
29 {
30 // Checks for virtual public derivation in exception classes.
31 // See:
32 // http://www.boost.org/more/error_handling.html
33 struct bad_non_virtual : virtual public std::exception { };
34
35 template<typename Exception, bool DefaultCons>
36 struct diamond_derivation_base;
37
38 template<typename Exception>
39 struct diamond_derivation_base<Exception, true>
40 {
41 struct diamond_derivation_error
42 : bad_non_virtual, Exception
43 {
44 diamond_derivation_error()
45 : bad_non_virtual(), Exception() { }
46 };
47 };
48
49 template<typename Exception>
50 struct diamond_derivation_base<Exception, false>
51 {
52 struct diamond_derivation_error
53 : bad_non_virtual, Exception
54 {
55 diamond_derivation_error()
56 : bad_non_virtual(), Exception("construct diamond") { }
57 };
58 };
59
60 template<typename Exception, bool DefaultCons>
61 struct diamond_derivation
62 : diamond_derivation_base<Exception, DefaultCons>
63 {
64 typedef diamond_derivation_base<Exception, DefaultCons> base_type;
65 typedef typename base_type::diamond_derivation_error error_type;
66
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.
71 static void test()
72 {
73 bool test __attribute__((unused)) = true;
74 try
75 { throw error_type(); }
76 catch (std::exception const&)
77 { VERIFY( false ); }
78 catch (...)
79 { VERIFY( true ); }
80 }
81 };
82
83 // Testing type requirements for template arguments.
84 struct NonDefaultConstructible
85 {
86 NonDefaultConstructible(int) { }
87 NonDefaultConstructible(const NonDefaultConstructible&) { }
88
89 #ifdef __GXX_EXPERIMENTAL_CXX0X__
90 // For std::iota.
91 NonDefaultConstructible&
92 operator++()
93 { return *this; }
94 #endif
95 };
96
97 // See: 20.1.1 Template argument requirements.
98 inline bool
99 operator==(const NonDefaultConstructible&, const NonDefaultConstructible&)
100 { return false; }
101
102 inline bool
103 operator<(const NonDefaultConstructible&, const NonDefaultConstructible&)
104 { return false; }
105
106 // For 26 numeric algorithms requirements, need addable,
107 // subtractable, multiplicable.
108 inline NonDefaultConstructible
109 operator+(const NonDefaultConstructible& lhs,
110 const NonDefaultConstructible& rhs)
111 { return NonDefaultConstructible(1); }
112
113 inline NonDefaultConstructible
114 operator-(const NonDefaultConstructible& lhs,
115 const NonDefaultConstructible& rhs)
116 { return NonDefaultConstructible(1); }
117
118 inline NonDefaultConstructible
119 operator*(const NonDefaultConstructible& lhs,
120 const NonDefaultConstructible& rhs)
121 { return NonDefaultConstructible(1); }
122
123 // Like unary_function, but takes no argument. (ie, void).
124 // Used for generator template parameter.
125 template<typename _Result>
126 struct void_function
127 {
128 typedef _Result result_type;
129
130 result_type
131 operator()() const
132 { return result_type(); }
133 };
134
135 template<>
136 struct void_function<NonDefaultConstructible>
137 {
138 typedef NonDefaultConstructible result_type;
139
140 result_type
141 operator()() const
142 { return result_type(2); }
143 };
144
145 }
146 #endif