]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/util/testsuite_tr1.h
target-supports.exp (check_function_available): Use -fno-builtin.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / testsuite_tr1.h
CommitLineData
493bc460
PC
1// -*- C++ -*-
2// Testing utilities for the tr1 testsuite.
3//
e4f32cb0
PC
4// Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010
5// Free Software Foundation, Inc.
493bc460
PC
6//
7// This file is part of the GNU ISO C++ Library. This library is free
8// software; you can redistribute it and/or modify it under the
9// terms of the GNU General Public License as published by the
748086b7 10// Free Software Foundation; either version 3, or (at your option)
493bc460
PC
11// any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License along
748086b7
JJ
19// with this library; see the file COPYING3. If not see
20// <http://www.gnu.org/licenses/>.
493bc460 21//
493bc460
PC
22
23#ifndef _GLIBCXX_TESTSUITE_TR1_H
24#define _GLIBCXX_TESTSUITE_TR1_H
25
105c6331 26#include <ext/type_traits.h>
ab44b018 27
493bc460 28namespace __gnu_test
0179f2c6 29{
493bc460 30 // For tr1/type_traits.
105c6331 31 template<template<typename> class Category, typename Type>
493bc460 32 bool
db5ff236 33 test_category(bool value)
493bc460
PC
34 {
35 bool ret = true;
db5ff236
PC
36 ret &= Category<Type>::value == value;
37 ret &= Category<const Type>::value == value;
38 ret &= Category<volatile Type>::value == value;
39 ret &= Category<const volatile Type>::value == value;
40 ret &= Category<Type>::type::value == value;
41 ret &= Category<const Type>::type::value == value;
42 ret &= Category<volatile Type>::type::value == value;
43 ret &= Category<const volatile Type>::type::value == value;
493bc460
PC
44 return ret;
45 }
0f910b4f 46
105c6331 47 template<template<typename> class Property, typename Type>
0f910b4f 48 bool
db5ff236 49 test_property(typename Property<Type>::value_type value)
0f910b4f
PC
50 {
51 bool ret = true;
db5ff236
PC
52 ret &= Property<Type>::value == value;
53 ret &= Property<Type>::type::value == value;
0f910b4f 54 return ret;
36651afe
PC
55 }
56
e7e93965
MM
57 // For testing tr1/type_traits/extent, which has a second template
58 // parameter.
59 template<template<typename, unsigned> class Property,
b0302c68 60 typename Type, unsigned Uint>
e7e93965
MM
61 bool
62 test_property(typename Property<Type, Uint>::value_type value)
63 {
64 bool ret = true;
65 ret &= Property<Type, Uint>::value == value;
66 ret &= Property<Type, Uint>::type::value == value;
67 return ret;
68 }
69
75995f37 70#ifdef __GXX_EXPERIMENTAL_CXX0X__
b0302c68 71 template<template<typename...> class Property, typename... Types>
75995f37 72 bool
b0302c68 73 test_property(typename Property<Types...>::value_type value)
75995f37
PC
74 {
75 bool ret = true;
b0302c68
PC
76 ret &= Property<Types...>::value == value;
77 ret &= Property<Types...>::type::value == value;
75995f37
PC
78 return ret;
79 }
b0302c68
PC
80#endif
81
d63a0e22 82 template<template<typename, typename> class Relationship,
0179f2c6 83 typename Type1, typename Type2>
d63a0e22 84 bool
db5ff236 85 test_relationship(bool value)
d63a0e22
PC
86 {
87 bool ret = true;
db5ff236
PC
88 ret &= Relationship<Type1, Type2>::value == value;
89 ret &= Relationship<Type1, Type2>::type::value == value;
d63a0e22
PC
90 return ret;
91 }
92
0f910b4f
PC
93 // Test types.
94 class ClassType { };
d63a0e22
PC
95 typedef const ClassType cClassType;
96 typedef volatile ClassType vClassType;
97 typedef const volatile ClassType cvClassType;
a9e7ba81 98
c150a271
PC
99 class DerivedType : public ClassType { };
100
dcd400b5 101 enum EnumType { e0 };
a9e7ba81
PC
102
103 struct ConvType
104 { operator int() const; };
f8023b78
PC
105
106 class AbstractClass
59cffcf6 107 {
cff001b2 108 virtual void rotate(int) = 0;
cff001b2 109 };
0179f2c6 110
442dca70 111 class PolymorphicClass
59cffcf6 112 {
cff001b2 113 virtual void rotate(int);
cff001b2 114 };
442dca70 115
59cffcf6 116 class DerivedPolymorphic : public PolymorphicClass { };
442dca70 117
22931aa4
PC
118 class VirtualDestructorClass
119 {
120 virtual ~VirtualDestructorClass();
121 };
122
9e38f702 123 union UnionType { };
0179f2c6 124
516ebd44 125 class IncompleteClass;
0179f2c6 126
75995f37
PC
127 struct ExplicitClass
128 {
129 ExplicitClass(double&);
130 explicit ExplicitClass(int&);
e4f32cb0 131 ExplicitClass(double&, int&, double&);
75995f37
PC
132 };
133
e4f32cb0
PC
134 struct NothrowExplicitClass
135 {
136 NothrowExplicitClass(double&) throw();
137 explicit NothrowExplicitClass(int&) throw();
138 NothrowExplicitClass(double&, int&, double&) throw();
139 };
140
141 struct ThrowExplicitClass
142 {
143 ThrowExplicitClass(double&) throw(int);
144 explicit ThrowExplicitClass(int&) throw(int);
145 ThrowExplicitClass(double&, int&, double&) throw(int);
146 };
147
148#ifdef __GXX_EXPERIMENTAL_CXX0X__
149 struct NoexceptExplicitClass
150 {
151 NoexceptExplicitClass(double&) noexcept(true);
152 explicit NoexceptExplicitClass(int&) noexcept(true);
153 NoexceptExplicitClass(double&, int&, double&) noexcept(true);
154 };
155
156 struct ExceptExplicitClass
157 {
158 ExceptExplicitClass(double&) noexcept(false);
159 explicit ExceptExplicitClass(int&) noexcept(false);
160 ExceptExplicitClass(double&, int&, double&) noexcept(false);
161 };
162#endif
163
54add740
PC
164 struct NType // neither trivial nor standard-layout
165 {
166 int i;
167 int j;
168 virtual ~NType();
169 };
170
171 struct TType // trivial but not standard-layout
172 {
173 int i;
174 private:
175 int j;
176 };
177
178 struct SLType // standard-layout but not trivial
179 {
180 int i;
181 int j;
182 ~SLType();
183 };
184
185 struct PODType // both trivial and standard-layout
186 {
187 int i;
188 int j;
189 };
190
9e38f702
PC
191 int truncate_float(float x) { return (int)x; }
192 long truncate_double(double x) { return (long)x; }
0179f2c6 193
9e38f702
PC
194 struct do_truncate_float_t
195 {
196 do_truncate_float_t()
197 {
198 ++live_objects;
199 }
0179f2c6 200
9e38f702
PC
201 do_truncate_float_t(const do_truncate_float_t&)
202 {
203 ++live_objects;
204 }
59cffcf6 205
9e38f702
PC
206 ~do_truncate_float_t()
207 {
208 --live_objects;
209 }
0179f2c6 210
9e38f702 211 int operator()(float x) { return (int)x; }
59cffcf6 212
9e38f702
PC
213 static int live_objects;
214 };
0179f2c6 215
9e38f702 216 int do_truncate_float_t::live_objects = 0;
0179f2c6 217
9e38f702
PC
218 struct do_truncate_double_t
219 {
220 do_truncate_double_t()
221 {
0179f2c6 222 ++live_objects;
9e38f702 223 }
0179f2c6 224
9e38f702
PC
225 do_truncate_double_t(const do_truncate_double_t&)
226 {
227 ++live_objects;
228 }
0179f2c6 229
9e38f702
PC
230 ~do_truncate_double_t()
231 {
232 --live_objects;
233 }
0179f2c6 234
9e38f702 235 long operator()(double x) { return (long)x; }
59cffcf6 236
9e38f702
PC
237 static int live_objects;
238 };
59cffcf6 239
9e38f702 240 int do_truncate_double_t::live_objects = 0;
59cffcf6 241
9e38f702
PC
242 struct X
243 {
244 int bar;
59cffcf6 245
9e38f702
PC
246 int foo() { return 1; }
247 int foo_c() const { return 2; }
248 int foo_v() volatile { return 3; }
249 int foo_cv() const volatile { return 4; }
250 };
90922b2d
PC
251
252 // For use in 8_c_compatibility.
253 template<typename R, typename T>
dcd400b5 254 typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value,
105c6331 255 bool>::__type
90922b2d
PC
256 check_ret_type(T)
257 { return true; }
258
59cffcf6 259} // namespace __gnu_test
493bc460
PC
260
261#endif // _GLIBCXX_TESTSUITE_TR1_H