]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/type_traits/test/aligned_storage_a2_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / type_traits / test / aligned_storage_a2_test.cpp
CommitLineData
7c673cae
FG
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#include "test.hpp"
12#include "check_integral_constant.hpp"
13#ifdef TEST_STD
14# include <type_traits>
15# include <boost/type_traits/type_with_alignment.hpp> // max_align and long_long_type
16#else
17# include <boost/type_traits/alignment_of.hpp>
18# include <boost/type_traits/aligned_storage.hpp>
19# include <boost/type_traits/is_pod.hpp>
20#endif
21
22template <class T>
23union must_be_pod
24{
25 int i;
26 T t;
27};
28
29template <class T>
30inline void no_unused_warning(const volatile T&)
31{
32}
33
34template <class T>
35void do_check(const T&)
36{
37 typedef typename tt::aligned_storage<T::value,T::value>::type t1;
b32b8144
FG
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
7c673cae 44 t1 as1 = { 0, };
b32b8144 45#endif
7c673cae
FG
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;
b32b8144
FG
56#if defined(BOOST_GCC) && (BOOST_GCC < 40800)
57 t2 as2 = {{{ 0, }}};
58#else
7c673cae 59 t2 as2 = { 0, };
b32b8144 60#endif
7c673cae
FG
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;
b32b8144
FG
74#if defined(BOOST_GCC) && (BOOST_GCC < 40800)
75 t3 as3 = {{{ 0, }}};
76#else
7c673cae 77 t3 as3 = { 0, };
b32b8144 78#endif
7c673cae
FG
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
91TT_TEST_BEGIN(type_with_alignment)
92
93do_check(tt::integral_constant<std::size_t,::tt::alignment_of<char>::value>());
94do_check(tt::integral_constant<std::size_t,::tt::alignment_of<short>::value>());
95do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int>::value>());
96do_check(tt::integral_constant<std::size_t,::tt::alignment_of<long>::value>());
97do_check(tt::integral_constant<std::size_t,::tt::alignment_of<float>::value>());
98do_check(tt::integral_constant<std::size_t,::tt::alignment_of<double>::value>());
99do_check(tt::integral_constant<std::size_t,::tt::alignment_of<long double>::value>());
100
101#ifdef BOOST_HAS_LONG_LONG
102do_check(tt::integral_constant<std::size_t,::tt::alignment_of< ::boost::long_long_type>::value>());
103#endif
104#ifdef BOOST_HAS_MS_INT64
105do_check(tt::integral_constant<std::size_t,::tt::alignment_of<__int64>::value>());
106#endif
107do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int[4]>::value>());
108do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int(*)(int)>::value>());
109do_check(tt::integral_constant<std::size_t,::tt::alignment_of<int*>::value>());
110do_check(tt::integral_constant<std::size_t,::tt::alignment_of<VB>::value>());
111do_check(tt::integral_constant<std::size_t,::tt::alignment_of<VD>::value>());
112do_check(tt::integral_constant<std::size_t,::tt::alignment_of<enum_UDT>::value>());
113do_check(tt::integral_constant<std::size_t,::tt::alignment_of<mf2>::value>());
114do_check(tt::integral_constant<std::size_t,::tt::alignment_of<POD_UDT>::value>());
115do_check(tt::integral_constant<std::size_t,::tt::alignment_of<empty_UDT>::value>());
116do_check(tt::integral_constant<std::size_t,::tt::alignment_of<union_UDT>::value>());
117do_check(tt::integral_constant<std::size_t,::tt::alignment_of<boost::detail::max_align>::value>());
118
119TT_TEST_END
120
121
122
123
124
125
126
127
128