blob: c87e99c46e808e90200b59eaa27f46b22e47e52e [file] [log] [blame]
Howard Hinnantc52f43e2010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc52f43e2010-08-22 00:59:46 +00007//
8//===----------------------------------------------------------------------===//
9
10// type_traits
11
12// aligned_storage
13
14#include <type_traits>
15
16int main()
17{
18 {
19 typedef std::aligned_storage<10, 1 >::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070020#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +000021 static_assert(std::is_same<std::aligned_storage_t<10, 1>, T1>::value, "" );
22#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000023 static_assert(std::alignment_of<T1>::value == 1, "");
24 static_assert(sizeof(T1) == 10, "");
25 }
26 {
27 typedef std::aligned_storage<10, 2 >::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070028#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +000029 static_assert(std::is_same<std::aligned_storage_t<10, 2>, T1>::value, "" );
30#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000031 static_assert(std::alignment_of<T1>::value == 2, "");
32 static_assert(sizeof(T1) == 10, "");
33 }
34 {
35 typedef std::aligned_storage<10, 4 >::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070036#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +000037 static_assert(std::is_same<std::aligned_storage_t<10, 4>, T1>::value, "" );
38#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000039 static_assert(std::alignment_of<T1>::value == 4, "");
40 static_assert(sizeof(T1) == 12, "");
41 }
42 {
43 typedef std::aligned_storage<10, 8 >::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070044#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +000045 static_assert(std::is_same<std::aligned_storage_t<10, 8>, T1>::value, "" );
46#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000047 static_assert(std::alignment_of<T1>::value == 8, "");
48 static_assert(sizeof(T1) == 16, "");
49 }
50 {
51 typedef std::aligned_storage<10, 16 >::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070052#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +000053 static_assert(std::is_same<std::aligned_storage_t<10, 16>, T1>::value, "" );
54#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000055 static_assert(std::alignment_of<T1>::value == 16, "");
56 static_assert(sizeof(T1) == 16, "");
57 }
58 {
59 typedef std::aligned_storage<10, 32 >::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070060#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +000061 static_assert(std::is_same<std::aligned_storage_t<10, 32>, T1>::value, "" );
62#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000063 static_assert(std::alignment_of<T1>::value == 32, "");
64 static_assert(sizeof(T1) == 32, "");
65 }
66 {
67 typedef std::aligned_storage<20, 32 >::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070068#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +000069 static_assert(std::is_same<std::aligned_storage_t<20, 32>, T1>::value, "" );
70#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000071 static_assert(std::alignment_of<T1>::value == 32, "");
72 static_assert(sizeof(T1) == 32, "");
73 }
74 {
75 typedef std::aligned_storage<40, 32 >::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070076#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +000077 static_assert(std::is_same<std::aligned_storage_t<40, 32>, T1>::value, "" );
78#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000079 static_assert(std::alignment_of<T1>::value == 32, "");
80 static_assert(sizeof(T1) == 64, "");
81 }
82 {
83 typedef std::aligned_storage<12, 16 >::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070084#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +000085 static_assert(std::is_same<std::aligned_storage_t<12, 16>, T1>::value, "" );
86#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000087 static_assert(std::alignment_of<T1>::value == 16, "");
88 static_assert(sizeof(T1) == 16, "");
89 }
90 {
91 typedef std::aligned_storage<1>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070092#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +000093 static_assert(std::is_same<std::aligned_storage_t<1>, T1>::value, "" );
94#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000095 static_assert(std::alignment_of<T1>::value == 1, "");
96 static_assert(sizeof(T1) == 1, "");
97 }
98 {
99 typedef std::aligned_storage<2>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700100#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +0000101 static_assert(std::is_same<std::aligned_storage_t<2>, T1>::value, "" );
102#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000103 static_assert(std::alignment_of<T1>::value == 2, "");
104 static_assert(sizeof(T1) == 2, "");
105 }
106 {
107 typedef std::aligned_storage<3>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700108#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +0000109 static_assert(std::is_same<std::aligned_storage_t<3>, T1>::value, "" );
110#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000111 static_assert(std::alignment_of<T1>::value == 2, "");
112 static_assert(sizeof(T1) == 4, "");
113 }
114 {
115 typedef std::aligned_storage<4>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700116#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +0000117 static_assert(std::is_same<std::aligned_storage_t<4>, T1>::value, "" );
118#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000119 static_assert(std::alignment_of<T1>::value == 4, "");
120 static_assert(sizeof(T1) == 4, "");
121 }
122 {
123 typedef std::aligned_storage<5>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700124#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +0000125 static_assert(std::is_same<std::aligned_storage_t<5>, T1>::value, "" );
126#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000127 static_assert(std::alignment_of<T1>::value == 4, "");
128 static_assert(sizeof(T1) == 8, "");
129 }
130 {
131 typedef std::aligned_storage<7>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700132#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +0000133 static_assert(std::is_same<std::aligned_storage_t<7>, T1>::value, "" );
134#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000135 static_assert(std::alignment_of<T1>::value == 4, "");
136 static_assert(sizeof(T1) == 8, "");
137 }
138 {
139 typedef std::aligned_storage<8>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700140#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +0000141 static_assert(std::is_same<std::aligned_storage_t<8>, T1>::value, "" );
142#endif
Howard Hinnant5544f7e2013-04-22 19:37:49 +0000143 static_assert(std::alignment_of<T1>::value == 8, "");
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000144 static_assert(sizeof(T1) == 8, "");
145 }
146 {
147 typedef std::aligned_storage<9>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700148#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +0000149 static_assert(std::is_same<std::aligned_storage_t<9>, T1>::value, "" );
150#endif
Howard Hinnant5544f7e2013-04-22 19:37:49 +0000151 static_assert(std::alignment_of<T1>::value == 8, "");
152 static_assert(sizeof(T1) == 16, "");
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000153 }
154 {
155 typedef std::aligned_storage<15>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700156#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +0000157 static_assert(std::is_same<std::aligned_storage_t<15>, T1>::value, "" );
158#endif
Howard Hinnant5544f7e2013-04-22 19:37:49 +0000159 static_assert(std::alignment_of<T1>::value == 8, "");
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000160 static_assert(sizeof(T1) == 16, "");
161 }
Nico Weber981b01d2014-06-04 16:25:58 +0000162 // Use alignof(std::max_align_t) below to find the max alignment instead of
163 // hardcoding it, because it's different on different platforms.
164 // (For example 8 on arm and 16 on x86.)
165#if __cplusplus < 201103L
166#define alignof __alignof__
167#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000168 {
169 typedef std::aligned_storage<16>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700170#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +0000171 static_assert(std::is_same<std::aligned_storage_t<16>, T1>::value, "" );
172#endif
Nico Weber981b01d2014-06-04 16:25:58 +0000173 static_assert(std::alignment_of<T1>::value == alignof(std::max_align_t),
174 "");
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000175 static_assert(sizeof(T1) == 16, "");
176 }
177 {
178 typedef std::aligned_storage<17>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700179#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +0000180 static_assert(std::is_same<std::aligned_storage_t<17>, T1>::value, "" );
181#endif
Nico Weber981b01d2014-06-04 16:25:58 +0000182 static_assert(std::alignment_of<T1>::value == alignof(std::max_align_t),
183 "");
184 static_assert(sizeof(T1) == 16 + alignof(std::max_align_t), "");
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000185 }
186 {
187 typedef std::aligned_storage<10>::type T1;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700188#if _LIBCPP_STD_VER > 11
Marshall Clow933afa92013-07-04 00:10:01 +0000189 static_assert(std::is_same<std::aligned_storage_t<10>, T1>::value, "" );
190#endif
Howard Hinnant5544f7e2013-04-22 19:37:49 +0000191 static_assert(std::alignment_of<T1>::value == 8, "");
192 static_assert(sizeof(T1) == 16, "");
Howard Hinnantc52f43e2010-08-22 00:59:46 +0000193 }
194}