]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/aligned_storage_a2_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / type_traits / test / aligned_storage_a2_test.cpp
1
2 #ifdef _MSC_VER
3 #pragma pack(2)
4 #endif
5
6 // (C) Copyright John Maddock 2000.
7 // Use, modification and distribution are subject to the
8 // Boost Software License, Version 1.0. (See accompanying file
9 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10
11 #ifdef TEST_STD
12 # include <type_traits>
13 # include <boost/type_traits/type_with_alignment.hpp> // max_align and long_long_type
14 #else
15 # include <boost/type_traits/alignment_of.hpp>
16 # include <boost/type_traits/aligned_storage.hpp>
17 # include <boost/type_traits/is_pod.hpp>
18 #endif
19 #include "test.hpp"
20 #include "check_integral_constant.hpp"
21
22 template <class T>
23 union must_be_pod
24 {
25 int i;
26 T t;
27 };
28
29 template <class T>
30 inline BOOST_TT_PROC void no_unused_warning(const volatile T&)
31 {
32 }
33
34 template <class T>
35 BOOST_TT_PROC void do_check(const T&)
36 {
37 typedef typename tt::aligned_storage<T::value,T::value>::type t1;
38 #if defined(BOOST_GCC) && (BOOST_GCC < 40800)
39 // In order to test this with warnings-as-errors with GCC, we need
40 // a slightly different initializer here to suppress spurious
41 // GCC warnings (ie to work around a GCC buglet).
42 t1 as1 = {{{ 0, }}};
43 #else
44 t1 as1 = { 0, };
45 #endif
46 must_be_pod<t1> pod1;
47 no_unused_warning(as1);
48 no_unused_warning(pod1);
49 #ifndef TEST_CUDA_DEVICE
50 BOOST_TEST_MESSAGE(typeid(t1).name());
51 BOOST_CHECK(::tt::alignment_of<t1>::value == T::value);
52 BOOST_CHECK(sizeof(t1) == T::value);
53 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
54 BOOST_CHECK(::tt::is_pod<t1>::value == true);
55 #endif
56 typedef typename tt::aligned_storage<T::value*2,T::value>::type t2;
57 #if defined(BOOST_GCC) && (BOOST_GCC < 40800)
58 t2 as2 = {{{ 0, }}};
59 #else
60 t2 as2 = { 0, };
61 #endif
62 must_be_pod<t2> pod2;
63 no_unused_warning(as2);
64 no_unused_warning(pod2);
65 BOOST_TEST_MESSAGE(typeid(t2).name());
66 BOOST_CHECK(::tt::alignment_of<t2>::value == T::value);
67 BOOST_CHECK(sizeof(t2) == T::value*2);
68 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
69 BOOST_CHECK(::tt::is_pod<t2>::value == true);
70 #endif
71
72 #ifndef TEST_STD
73 // Non-Tr1 behaviour:
74 typedef typename tt::aligned_storage<T::value,(std::size_t)(-1L)>::type t3;
75 #if defined(BOOST_GCC) && (BOOST_GCC < 40800)
76 t3 as3 = {{{ 0, }}};
77 #else
78 t3 as3 = { 0, };
79 #endif
80 must_be_pod<t3> pod3;
81 no_unused_warning(as3);
82 no_unused_warning(pod3);
83 BOOST_TEST_MESSAGE(typeid(t3).name());
84 BOOST_CHECK(::tt::alignment_of<t3>::value == ::tt::alignment_of< ::boost::detail::max_align>::value);
85 BOOST_CHECK((sizeof(t3) % T::value) == 0);
86 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
87 BOOST_CHECK(::tt::is_pod<t3>::value == true);
88 #endif
89 #endif
90 #endif
91 }
92
93 TT_TEST_BEGIN(type_with_alignment)
94
95 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<char>::value>());
96 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<short>::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<long>::value>());
99 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<float>::value>());
100 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<double>::value>());
101 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<long double>::value>());
102
103 #ifdef BOOST_HAS_LONG_LONG
104 do_check(tt::integral_constant<std::size_t,::tt::alignment_of< ::boost::long_long_type>::value>());
105 #endif
106 #ifdef BOOST_HAS_MS_INT64
107 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<__int64>::value>());
108 #endif
109 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int[4]>::value>());
110 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int(*)(int)>::value>());
111 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int*>::value>());
112 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<VB>::value>());
113 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<VD>::value>());
114 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<enum_UDT>::value>());
115 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<mf2>::value>());
116 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<POD_UDT>::value>());
117 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<empty_UDT>::value>());
118 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<union_UDT>::value>());
119 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<boost::detail::max_align>::value>());
120
121 TT_TEST_END
122
123
124
125
126
127
128
129
130