]>
Commit | Line | Data |
---|---|---|
0bb81a93 BK |
1 | // -*- C++ -*- |
2 | // Exception testing utils for the C++ library testsuite. | |
3 | // | |
4 | // Copyright (C) 2007 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 2, 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 COPYING. If not, write to the Free | |
19 | // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | |
20 | // USA. | |
21 | // | |
22 | // As a special exception, you may use this file as part of a free software | |
23 | // library without restriction. Specifically, if other files instantiate | |
24 | // templates or use macros or inline functions from this file, or you compile | |
25 | // this file and link it with other files to produce an executable, this | |
26 | // file does not by itself cause the resulting executable to be covered by | |
27 | // the GNU General Public License. This exception does not however | |
28 | // invalidate any other reasons why the executable file might be covered by | |
29 | // the GNU General Public License. | |
30 | ||
31 | #include <testsuite_hooks.h> | |
32 | ||
4f99f3d0 BK |
33 | #ifndef _TESTSUITE_API |
34 | #define _TESTSUITE_API 1 | |
0bb81a93 BK |
35 | |
36 | namespace __gnu_test | |
37 | { | |
38 | // Checks for virtual public derivation in exception classes. | |
39 | // See: | |
40 | // http://www.boost.org/more/error_handling.html | |
41 | struct bad_non_virtual : virtual public std::exception { }; | |
42 | ||
43 | template<typename Exception, bool DefaultCons> | |
44 | struct diamond_derivation_base; | |
45 | ||
46 | template<typename Exception> | |
47 | struct diamond_derivation_base<Exception, true> | |
48 | { | |
49 | struct diamond_derivation_error: bad_non_virtual, Exception | |
50 | { | |
51 | diamond_derivation_error() : bad_non_virtual(), Exception() { } | |
52 | }; | |
53 | }; | |
54 | ||
55 | template<typename Exception> | |
56 | struct diamond_derivation_base<Exception, false> | |
57 | { | |
58 | struct diamond_derivation_error: bad_non_virtual, Exception | |
59 | { | |
60 | diamond_derivation_error() | |
61 | : bad_non_virtual(), Exception("construct diamond") { } | |
62 | }; | |
63 | }; | |
64 | ||
65 | template<typename Exception, bool DefaultCons> | |
66 | struct diamond_derivation: diamond_derivation_base<Exception, DefaultCons> | |
67 | { | |
68 | typedef diamond_derivation_base<Exception, DefaultCons> base_type; | |
69 | typedef typename base_type::diamond_derivation_error error_type; | |
70 | ||
71 | static void test() | |
72 | { | |
73 | bool test __attribute__((unused)) = true; | |
74 | try { throw error_type(); } | |
75 | catch (std::exception const& e) { } | |
76 | catch (...) | |
77 | { VERIFY( false ); } | |
78 | } | |
79 | }; | |
4f99f3d0 BK |
80 | |
81 | // Testing type requirements for template arguments. | |
82 | struct NonDefaultConstructible | |
83 | { | |
84 | NonDefaultConstructible(int) { } | |
85 | NonDefaultConstructible(const NonDefaultConstructible&) { } | |
86 | }; | |
87 | ||
88 | // See: 20.1.1 Template argument requirements. | |
89 | inline bool | |
90 | operator==(const NonDefaultConstructible&, const NonDefaultConstructible&) | |
91 | { return false; } | |
92 | ||
93 | inline bool | |
94 | operator<(const NonDefaultConstructible&, const NonDefaultConstructible&) | |
95 | { return false; } | |
96 | ||
97 | // For 26 numeric algorithms requirements, need addable, | |
98 | // subtractable, multiplicable. | |
99 | inline NonDefaultConstructible | |
100 | operator+(const NonDefaultConstructible& lhs, | |
101 | const NonDefaultConstructible& rhs) | |
102 | { return NonDefaultConstructible(1); } | |
103 | ||
104 | inline NonDefaultConstructible | |
105 | operator-(const NonDefaultConstructible& lhs, | |
106 | const NonDefaultConstructible& rhs) | |
107 | { return NonDefaultConstructible(1); } | |
108 | ||
109 | inline NonDefaultConstructible | |
110 | operator*(const NonDefaultConstructible& lhs, | |
111 | const NonDefaultConstructible& rhs) | |
112 | { return NonDefaultConstructible(1); } | |
113 | ||
114 | // Like unary_function, but takes no argument. (ie, void). | |
115 | // Used for generator template parameter. | |
116 | template<typename _Result> | |
117 | struct void_function | |
118 | { | |
119 | typedef _Result result_type; | |
120 | ||
121 | result_type | |
122 | operator()() const | |
123 | { | |
124 | result_type r; | |
125 | return r; | |
126 | } | |
127 | }; | |
128 | ||
129 | template<> | |
130 | struct void_function<NonDefaultConstructible> | |
131 | { | |
132 | typedef NonDefaultConstructible result_type; | |
133 | ||
134 | result_type | |
135 | operator()() const | |
136 | { return result_type(2); } | |
137 | }; | |
138 | ||
0bb81a93 BK |
139 | } |
140 | #endif |