]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/aligned_storage_a2_test.cpp
import quincy beta 17.1.0
[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 void no_unused_warning(const volatile T&)
31 {
32 }
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 #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 BOOST_TEST_MESSAGE(typeid(t1).name());
50 BOOST_CHECK(::tt::alignment_of<t1>::value == T::value);
51 BOOST_CHECK(sizeof(t1) == T::value);
52 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
53 BOOST_CHECK(::tt::is_pod<t1>::value == true);
54 #endif
55 typedef typename tt::aligned_storage<T::value*2,T::value>::type t2;
56 #if defined(BOOST_GCC) && (BOOST_GCC < 40800)
57 t2 as2 = {{{ 0, }}};
58 #else
59 t2 as2 = { 0, };
60 #endif
61 must_be_pod<t2> pod2;
62 no_unused_warning(as2);
63 no_unused_warning(pod2);
64 BOOST_TEST_MESSAGE(typeid(t2).name());
65 BOOST_CHECK(::tt::alignment_of<t2>::value == T::value);
66 BOOST_CHECK(sizeof(t2) == T::value*2);
67 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
68 BOOST_CHECK(::tt::is_pod<t2>::value == true);
69 #endif
70
71 #ifndef TEST_STD
72 // Non-Tr1 behaviour:
73 typedef typename tt::aligned_storage<T::value,(std::size_t)(-1L)>::type t3;
74 #if defined(BOOST_GCC) && (BOOST_GCC < 40800)
75 t3 as3 = {{{ 0, }}};
76 #else
77 t3 as3 = { 0, };
78 #endif
79 must_be_pod<t3> pod3;
80 no_unused_warning(as3);
81 no_unused_warning(pod3);
82 BOOST_TEST_MESSAGE(typeid(t3).name());
83 BOOST_CHECK(::tt::alignment_of<t3>::value == ::tt::alignment_of< ::boost::detail::max_align>::value);
84 BOOST_CHECK((sizeof(t3) % T::value) == 0);
85 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
86 BOOST_CHECK(::tt::is_pod<t3>::value == true);
87 #endif
88 #endif
89 }
90
91 TT_TEST_BEGIN(type_with_alignment)
92
93 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<char>::value>());
94 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<short>::value>());
95 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int>::value>());
96 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<long>::value>());
97 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<float>::value>());
98 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<double>::value>());
99 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<long double>::value>());
100
101 #ifdef BOOST_HAS_LONG_LONG
102 do_check(tt::integral_constant<std::size_t,::tt::alignment_of< ::boost::long_long_type>::value>());
103 #endif
104 #ifdef BOOST_HAS_MS_INT64
105 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<__int64>::value>());
106 #endif
107 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int[4]>::value>());
108 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int(*)(int)>::value>());
109 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int*>::value>());
110 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<VB>::value>());
111 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<VD>::value>());
112 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<enum_UDT>::value>());
113 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<mf2>::value>());
114 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<POD_UDT>::value>());
115 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<empty_UDT>::value>());
116 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<union_UDT>::value>());
117 do_check(tt::integral_constant<std::size_t,::tt::alignment_of<boost::detail::max_align>::value>());
118
119 TT_TEST_END
120
121
122
123
124
125
126
127
128