]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/is_copy_constructible_test.cpp
1 // (C) Copyright John Maddock 2000.
2 // (C) Copyright Antony Polukhin 2013.
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 # include <type_traits>
10 # include <boost/type_traits/is_copy_constructible.hpp>
13 #include "check_integral_constant.hpp"
15 #include <boost/move/core.hpp>
22 // MSVC can not generate neither default constructor, nor assignment operator,
23 // nor copy constructor for `has2` type. Suppressing those warnings is essential,
24 // because we treat warnings as errors in those tests
25 #if (defined _MSC_VER)
26 # pragma warning( push )
27 # pragma warning( disable : 4510 4512 4610)
31 explicit has2(const int& val
) : i(val
) {}
33 #if (defined _MSC_VER)
34 # pragma warning( pop )
42 struct has4
{ // Copy constructor must be generated by compiler
46 struct has_not
: public boost::noncopyable
{
47 typedef boost::noncopyable base_t
;
48 has_not() : base_t() {}
51 #ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
55 has_not2(has_not2
&) = delete;
60 has_not3(const has_not3
&) = delete;
63 #endif // BOOST_NO_CXX11_DELETED_FUNCTIONS
65 struct has_not4
: private boost::noncopyable
{
66 typedef boost::noncopyable base_t
;
67 has_not4() : base_t() {}
69 has_not4(const has_not4
&);
74 BOOST_MOVABLE_BUT_NOT_COPYABLE(has_not5
)
78 TT_TEST_BEGIN(is_copy_constructible
)
80 // Main part of the test
81 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<has
>::value
, true);
82 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<has2
>::value
, true);
83 // Only constructible from has3& not from const-reference, this only works if we have decltype:
84 #if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800)
85 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<has3
>::value
, false);
87 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<has4
>::value
, true);
88 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<has_not
>::value
, false);
89 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_INTEL_CXX_VERSION)
90 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<has_not2
>::value
, false);
91 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<has_not3
>::value
, false);
93 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<has_not4
>::value
, false);
95 // Requires some basic support from Boost.Move in C++03
96 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<has_not5
>::value
, false);
98 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<bool>::value
, true);
99 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<bool const>::value
, true);
101 // unspecified behaviour:
102 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<bool volatile>::value
, true);
103 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<bool const volatile>::value
, true);
106 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<signed char>::value
, true);
107 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<signed char const>::value
, true);
109 // unspecified behaviour:
110 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<signed char volatile>::value
, true);
111 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<signed char const volatile>::value
, true);
113 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned char>::value
, true);
114 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<char>::value
, true);
115 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned char const>::value
, true);
116 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<char const>::value
, true);
118 // unspecified behaviour:
119 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned char volatile>::value
, true);
120 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<char volatile>::value
, true);
121 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned char const volatile>::value
, true);
122 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<char const volatile>::value
, true);
125 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned short>::value
, true);
126 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<short>::value
, true);
127 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned short const>::value
, true);
128 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<short const>::value
, true);
130 // unspecified behaviour:
131 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned short volatile>::value
, true);
132 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<short volatile>::value
, true);
133 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned short const volatile>::value
, true);
134 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<short const volatile>::value
, true);
137 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned int>::value
, true);
138 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<int>::value
, true);
139 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned int const>::value
, true);
140 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<int const>::value
, true);
142 // unspecified behaviour:
143 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned int volatile>::value
, true);
144 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<int volatile>::value
, true);
145 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned int const volatile>::value
, true);
146 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<int const volatile>::value
, true);
149 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned long>::value
, true);
150 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<long>::value
, true);
151 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned long const>::value
, true);
152 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<long const>::value
, true);
154 // unspecified behaviour:
155 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned long volatile>::value
, true);
156 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<long volatile>::value
, true);
157 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned long const volatile>::value
, true);
158 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<long const volatile>::value
, true);
161 #ifdef BOOST_HAS_LONG_LONG
163 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
< ::boost::ulong_long_type
>::value
, true);
164 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
< ::boost::long_long_type
>::value
, true);
165 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
< ::boost::ulong_long_type
const>::value
, true);
166 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
< ::boost::long_long_type
const>::value
, true);
168 // unspecified behaviour:
169 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
< ::boost::ulong_long_type
volatile>::value
, true);
170 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
< ::boost::long_long_type
volatile>::value
, true);
171 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
< ::boost::ulong_long_type
const volatile>::value
, true);
172 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
< ::boost::long_long_type
const volatile>::value
, true);
176 #ifdef BOOST_HAS_MS_INT64
178 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int8
>::value
, true);
179 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int8
>::value
, true);
180 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int8
const>::value
, true);
181 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int8
const>::value
, true);
183 // unspecified behaviour:
184 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int8
volatile>::value
, true);
185 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int8
volatile>::value
, true);
186 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int8
const volatile>::value
, true);
187 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int8
const volatile>::value
, true);
190 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int16
>::value
, true);
191 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int16
>::value
, true);
192 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int16
const>::value
, true);
193 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int16
const>::value
, true);
195 // unspecified behaviour:
196 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int16
volatile>::value
, true);
197 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int16
volatile>::value
, true);
198 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int16
const volatile>::value
, true);
199 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int16
const volatile>::value
, true);
202 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int32
>::value
, true);
203 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int32
>::value
, true);
204 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int32
const>::value
, true);
205 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int32
const>::value
, true);
207 // unspecified behaviour:
208 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int32
volatile>::value
, true);
209 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int32
volatile>::value
, true);
210 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int32
const volatile>::value
, true);
211 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int32
const volatile>::value
, true);
214 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int64
>::value
, true);
215 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int64
>::value
, true);
216 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int64
const>::value
, true);
217 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int64
const>::value
, true);
219 // unspecified behaviour:
220 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int64
volatile>::value
, true);
221 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int64
volatile>::value
, true);
222 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<unsigned __int64
const volatile>::value
, true);
223 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<__int64
const volatile>::value
, true);
227 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<float>::value
, true);
228 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<float const>::value
, true);
230 // unspecified behaviour:
231 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<float volatile>::value
, true);
232 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<float const volatile>::value
, true);
235 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<double>::value
, true);
236 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<double const>::value
, true);
238 // unspecified behaviour:
239 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<double volatile>::value
, true);
240 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<double const volatile>::value
, true);
243 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<long double>::value
, true);
244 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<long double const>::value
, true);
246 // unspecified behaviour:
247 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<long double volatile>::value
, true);
248 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<long double const volatile>::value
, true);
251 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<int>::value
, true);
252 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<void*>::value
, true);
253 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<int*const>::value
, true);
254 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<f1
>::value
, true);
255 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<f2
>::value
, true);
256 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<f3
>::value
, true);
257 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<mf1
>::value
, true);
258 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<mf2
>::value
, true);
259 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<mf3
>::value
, true);
260 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<mp
>::value
, true);
261 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<cmf
>::value
, true);
262 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<enum_UDT
>::value
, true);
264 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<int&>::value
, true);
265 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
266 // This is debatable, we used to insist this was true, but copy-constructibility
267 // implies copying a constant-object, and that isn't the case here:
268 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<int&&>::value
, false);
270 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<const int&>::value
, true);
273 // Following three tests may give different results because of compiler and C++03/C++11.
274 // On C++11 compiler following code:
275 // int c[2][4][5][6][3];
276 // int b[2][4][5][6][3] = std::move(c);
277 // does not compile, so we expect `false` to be the result of those three tests.
278 BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<int[2]>::value
, false, true);
279 BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<int[3][2]>::value
, false, true);
280 BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<int[2][4][5][6][3]>::value
, false, true);
282 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<UDT
>::value
, true);
283 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<void>::value
, false);
285 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<empty_POD_UDT
>::value
, true);
286 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<POD_UDT
>::value
, true);
287 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<POD_union_UDT
>::value
, true);
288 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<empty_POD_union_UDT
>::value
, true);
289 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<nothrow_copy_UDT
>::value
, true);
290 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<nothrow_assign_UDT
>::value
, true);
291 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<nothrow_construct_UDT
>::value
, true);
293 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_NOEXCEPT)
294 // Copy constructor of nothrow_move_UDT is implicitly deleted because of user declared move constructor.
295 // Hovewer not all compilers implement that feature correctly.
296 BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::is_copy_constructible
<nothrow_move_UDT
>::value
, false, true);
299 //TODO: What do we need to do in this situation?
300 //BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<test_abc1>::value, true);