]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/alignment_of_test.cpp
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)
8 #include "check_integral_constant.hpp"
10 # include <type_traits>
12 # include <boost/type_traits/alignment_of.hpp>
16 // Need to defined some member function for empty_UDT,
17 // we don't want to put these in the test.hpp as that
18 // causes overly-clever compilers to figure out that they can't throw
19 // which in turn breaks other tests.
21 empty_UDT::empty_UDT(){}
22 empty_UDT::~empty_UDT(){}
23 empty_UDT::empty_UDT(const empty_UDT
&){}
24 empty_UDT
& empty_UDT::operator=(const empty_UDT
&){ return *this; }
25 bool empty_UDT::operator==(const empty_UDT
&)const{ return true; }
28 // VC++ emits an awful lot of warnings unless we define these:
30 # pragma warning(disable:4244)
32 // What follows here is the test case for issue 1946.
34 #include <boost/function.hpp>
35 // This kind of packing is set within MSVC 9.0 headers.
36 // E.g. std::ostream has it.
39 // The issue is gone if Root has no data members
40 struct Root
{ int a
; };
41 // The issue is gone if Root is inherited non-virtually
42 struct A
: virtual public Root
{};
46 // This class has 8-byte alignment but is 44 bytes in size, which means
47 // that elements in an array of this type will not actually be 8 byte
48 // aligned. This appears to be an MSVC bug, and throws off our
49 // alignment calculations: causing us to report a non-sensical 12-byte
50 // alignment for this type. This is fixed by using the native __alignof
57 // The issue is gone if the type is not a boost::function. The signature doesn't matter.
58 typedef boost::function0
< void > function_type
;
59 function_type m_function
;
70 static std::ptrdiff_t get()
72 static align_calc
<T
> a
;
73 return reinterpret_cast<const char*>(&(a
.instance
)) - reinterpret_cast<const char*>(&(a
.padding
));
77 #define ALIGNOF(x) align_calc< x>::get()
79 TT_TEST_BEGIN(alignment_of
)
82 // This test is not required to work for non-boost implementations:
83 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<void>::value
, 0);
85 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<char>::value
, ALIGNOF(char));
86 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<short>::value
, ALIGNOF(short));
87 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<int>::value
, ALIGNOF(int));
88 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<long>::value
, ALIGNOF(long));
89 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<float>::value
, ALIGNOF(float));
90 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<double>::value
, ALIGNOF(double));
91 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<long double>::value
, ALIGNOF(long double));
92 #ifdef BOOST_HAS_LONG_LONG
93 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
< ::boost::long_long_type
>::value
, ALIGNOF(::boost::long_long_type
));
95 #ifdef BOOST_HAS_MS_INT64
96 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<__int64
>::value
, ALIGNOF(__int64
));
98 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<int[4]>::value
, ALIGNOF(int[4]));
99 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<int(*)(int)>::value
, ALIGNOF(int(*)(int)));
100 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<int*>::value
, ALIGNOF(int*));
101 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<VB
>::value
, ALIGNOF(VB
));
102 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<VD
>::value
, ALIGNOF(VD
));
103 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<enum_UDT
>::value
, ALIGNOF(enum_UDT
));
104 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<mf2
>::value
, ALIGNOF(mf2
));
105 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<POD_UDT
>::value
, ALIGNOF(POD_UDT
));
106 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<empty_UDT
>::value
, ALIGNOF(empty_UDT
));
107 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<union_UDT
>::value
, ALIGNOF(union_UDT
));
109 #if defined(BOOST_MSVC) && (BOOST_MSVC >= 1400)
110 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of
<issue1946
>::value
, ALIGNOF(issue1946
));