]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/aligned_storage_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / type_traits / test / aligned_storage_test.cpp
1
2 // (C) Copyright John Maddock 2000.
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 #include "test.hpp"
8 #include "check_integral_constant.hpp"
9 #ifdef TEST_STD
10 # include <type_traits>
11 # include <boost/type_traits/type_with_alignment.hpp> // max_align and long_long_type
12 #else
13 # include <boost/type_traits/alignment_of.hpp>
14 # include <boost/type_traits/aligned_storage.hpp>
15 # include <boost/type_traits/is_pod.hpp>
16 #endif
17
18 template <class T>
19 union must_be_pod
20 {
21 int i;
22 T t;
23 };
24
25 template <class T>
26 inline void no_unused_warning(const volatile T&)
27 {
28 }
29
30 #if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(BOOST_INTEL)
31 #pragma GCC diagnostic ignored "-Wmissing-braces"
32 #endif
33
34 template <class T>
35 void do_check(const T&)
36 {
37 typedef typename tt::aligned_storage<T::value,T::value>::type t1;
38 t1 as1 = { 0, };
39 must_be_pod<t1> pod1;
40 no_unused_warning(as1);
41 no_unused_warning(pod1);
42 BOOST_TEST_MESSAGE(typeid(t1).name());
43 BOOST_CHECK(::tt::alignment_of<t1>::value == T::value);
44 BOOST_CHECK(sizeof(t1) == T::value);
45 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
46 BOOST_CHECK(::tt::is_pod<t1>::value == true);
47 #endif
48 typedef typename tt::aligned_storage<T::value*2,T::value>::type t2;
49 t2 as2 = { 0, };
50 must_be_pod<t2> pod2;
51 no_unused_warning(as2);
52 no_unused_warning(pod2);
53 BOOST_TEST_MESSAGE(typeid(t2).name());
54 BOOST_CHECK(::tt::alignment_of<t2>::value == T::value);
55 BOOST_CHECK(sizeof(t2) == T::value*2);
56 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
57 BOOST_CHECK(::tt::is_pod<t2>::value == true);
58 #endif
59
60 #ifndef TEST_STD
61 // Non-Tr1 behaviour:
62 typedef typename tt::aligned_storage<T::value, ~static_cast<std::size_t>(0UL)>::type t3;
63 t3 as3 = { 0, };
64 must_be_pod<t3> pod3;
65 no_unused_warning(as3);
66 no_unused_warning(pod3);
67 BOOST_TEST_MESSAGE(typeid(t3).name());
68 BOOST_CHECK(::tt::alignment_of<t3>::value == ::tt::alignment_of< ::boost::detail::max_align>::value);
69 BOOST_CHECK((sizeof(t3) % T::value) == 0);
70 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
71 BOOST_CHECK(::tt::is_pod<t3>::value == true);
72 #endif
73 BOOST_CHECK(as3.address() == &as3);
74 const t3 as4 = { 0, };
75 BOOST_CHECK(as4.address() == static_cast<const void*>(&as4));
76 #endif
77 }
78
79 TT_TEST_BEGIN(type_with_alignment)
80
81 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<char>::value>());
82 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<short>::value>());
83 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int>::value>());
84 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<long>::value>());
85 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<float>::value>());
86 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<double>::value>());
87 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<long double>::value>());
88
89 #ifdef BOOST_HAS_LONG_LONG
90 do_check(tt::integral_constant<std::size_t,::tt::alignment_of< ::boost::long_long_type>::value>());
91 #endif
92 #ifdef BOOST_HAS_MS_INT64
93 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<__int64>::value>());
94 #endif
95 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int[4]>::value>());
96 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int(*)(int)>::value>());
97 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int*>::value>());
98 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<VB>::value>());
99 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<VD>::value>());
100 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<enum_UDT>::value>());
101 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<mf2>::value>());
102 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<POD_UDT>::value>());
103 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<empty_UDT>::value>());
104 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<union_UDT>::value>());
105 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<boost::detail::max_align>::value>());
106
107 TT_TEST_END
108
109
110
111
112
113
114
115
116