]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/alignment_of_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / type_traits / test / alignment_of_test.cpp
1
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)
6
7 #include "test.hpp"
8 #include "check_integral_constant.hpp"
9 #ifdef TEST_STD
10 # include <type_traits>
11 #else
12 # include <boost/type_traits/alignment_of.hpp>
13 #endif
14
15 //
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.
20 //
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; }
26
27 //
28 // VC++ emits an awful lot of warnings unless we define these:
29 #ifdef BOOST_MSVC
30 # pragma warning(disable:4244)
31 //
32 // What follows here is the test case for issue 1946.
33 //
34 #include <boost/function.hpp>
35 // This kind of packing is set within MSVC 9.0 headers.
36 // E.g. std::ostream has it.
37 #pragma pack(push,8)
38
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 {};
43
44 #pragma pack(pop)
45 //
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
51 // operator.
52 //
53 class issue1946 :
54 public A
55 {
56 public:
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;
60 };
61
62 #endif
63
64
65 template <class T>
66 struct align_calc
67 {
68 char padding;
69 T instance;
70 static std::ptrdiff_t get()
71 {
72 static align_calc<T> a;
73 return reinterpret_cast<const char*>(&(a.instance)) - reinterpret_cast<const char*>(&(a.padding));
74 }
75 };
76
77 #define ALIGNOF(x) align_calc< x>::get()
78
79 TT_TEST_BEGIN(alignment_of)
80
81 #ifndef TEST_STD
82 // This test is not required to work for non-boost implementations:
83 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<void>::value, 0);
84 #endif
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));
94 #endif
95 #ifdef BOOST_HAS_MS_INT64
96 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<__int64>::value, ALIGNOF(__int64));
97 #endif
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));
108
109 #if defined(BOOST_MSVC) && (BOOST_MSVC >= 1400)
110 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<issue1946>::value, ALIGNOF(issue1946));
111 #endif
112
113 TT_TEST_END
114
115
116
117
118
119
120
121