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