]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/is_copy_constructible_test.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / 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)
6
7 #ifdef TEST_STD
8 # include <type_traits>
9 #else
10 # include <boost/type_traits/is_copy_constructible.hpp>
11 #endif
12 #include "test.hpp"
13 #include "check_integral_constant.hpp"
14
15 #include <boost/move/core.hpp>
16
17 struct has {
18 has(){}
19 has(const has&){}
20 };
21
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)
28 #endif
29 struct has2 {
30 const int& i;
31 explicit has2(const int& val) : i(val) {}
32 };
33 #if (defined _MSC_VER)
34 # pragma warning( pop )
35 #endif
36
37 struct has3 {
38 has3(has3&){}
39 };
40
41
42 struct has4 { // Copy constructor must be generated by compiler
43 has4(has4*){}
44 };
45
46 struct has_not: public boost::noncopyable {
47 typedef boost::noncopyable base_t;
48 has_not() : base_t() {}
49 };
50
51 #ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS
52
53 struct has_not2 {
54 has_not2() {}
55 has_not2(has_not2&) = delete;
56 };
57
58 struct has_not3 {
59 has_not3() {}
60 has_not3(const has_not3&) = delete;
61 };
62
63 #endif // BOOST_NO_CXX11_DELETED_FUNCTIONS
64
65 struct has_not4: private boost::noncopyable {
66 typedef boost::noncopyable base_t;
67 has_not4() : base_t() {}
68 private:
69 has_not4(const has_not4&);
70 };
71
72 struct has_not5 {
73 private:
74 BOOST_MOVABLE_BUT_NOT_COPYABLE(has_not5)
75 };
76
77
78 TT_TEST_BEGIN(is_copy_constructible)
79
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);
86 #endif
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);
92 #endif
93 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<has_not4>::value, false);
94
95 // Requires some basic support from Boost.Move in C++03
96 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<has_not5>::value, false);
97
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);
100 #ifndef TEST_STD
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);
104 #endif
105
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);
108 #ifndef TEST_STD
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);
112 #endif
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);
117 #ifndef TEST_STD
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);
123 #endif
124
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);
129 #ifndef TEST_STD
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);
135 #endif
136
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);
141 #ifndef TEST_STD
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);
147 #endif
148
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);
153 #ifndef TEST_STD
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);
159 #endif
160
161 #ifdef BOOST_HAS_LONG_LONG
162
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);
167 #ifndef TEST_STD
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);
173 #endif
174 #endif
175
176 #ifdef BOOST_HAS_MS_INT64
177
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);
182 #ifndef TEST_STD
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);
188 #endif
189
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);
194 #ifndef TEST_STD
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);
200 #endif
201
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);
206 #ifndef TEST_STD
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);
212 #endif
213
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);
218 #ifndef TEST_STD
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);
224 #endif
225 #endif
226
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);
229 #ifndef TEST_STD
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);
233 #endif
234
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);
237 #ifndef TEST_STD
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);
241 #endif
242
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);
245 #ifndef TEST_STD
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);
249 #endif
250
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);
263
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);
269 #endif
270 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<const int&>::value, true);
271
272
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);
281
282 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<UDT>::value, true);
283 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<void>::value, false);
284
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);
292
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);
297 #endif
298
299 //TODO: What do we need to do in this situation?
300 //BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<test_abc1>::value, true);
301
302
303 TT_TEST_END
304
305
306