• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // type_traits
11 
12 // aligned_storage
13 
14 #include <type_traits>
15 #include <cstddef>       // for std::max_align_t
16 #include "test_macros.h"
17 
main()18 int main()
19 {
20     {
21     typedef std::aligned_storage<10, 1 >::type T1;
22 #if TEST_STD_VER > 11
23     static_assert(std::is_same<std::aligned_storage_t<10, 1>, T1>::value, "" );
24 #endif
25     static_assert(std::alignment_of<T1>::value == 1, "");
26     static_assert(sizeof(T1) == 10, "");
27     }
28     {
29     typedef std::aligned_storage<10, 2 >::type T1;
30 #if TEST_STD_VER > 11
31     static_assert(std::is_same<std::aligned_storage_t<10, 2>, T1>::value, "" );
32 #endif
33     static_assert(std::alignment_of<T1>::value == 2, "");
34     static_assert(sizeof(T1) == 10, "");
35     }
36     {
37     typedef std::aligned_storage<10, 4 >::type T1;
38 #if TEST_STD_VER > 11
39     static_assert(std::is_same<std::aligned_storage_t<10, 4>, T1>::value, "" );
40 #endif
41     static_assert(std::alignment_of<T1>::value == 4, "");
42     static_assert(sizeof(T1) == 12, "");
43     }
44     {
45     typedef std::aligned_storage<10, 8 >::type T1;
46 #if TEST_STD_VER > 11
47     static_assert(std::is_same<std::aligned_storage_t<10, 8>, T1>::value, "" );
48 #endif
49     static_assert(std::alignment_of<T1>::value == 8, "");
50     static_assert(sizeof(T1) == 16, "");
51     }
52     {
53     typedef std::aligned_storage<10, 16 >::type T1;
54 #if TEST_STD_VER > 11
55     static_assert(std::is_same<std::aligned_storage_t<10, 16>, T1>::value, "" );
56 #endif
57     static_assert(std::alignment_of<T1>::value == 16, "");
58     static_assert(sizeof(T1) == 16, "");
59     }
60     {
61     typedef std::aligned_storage<10, 32 >::type T1;
62 #if TEST_STD_VER > 11
63     static_assert(std::is_same<std::aligned_storage_t<10, 32>, T1>::value, "" );
64 #endif
65     static_assert(std::alignment_of<T1>::value == 32, "");
66     static_assert(sizeof(T1) == 32, "");
67     }
68     {
69     typedef std::aligned_storage<20, 32 >::type T1;
70 #if TEST_STD_VER > 11
71     static_assert(std::is_same<std::aligned_storage_t<20, 32>, T1>::value, "" );
72 #endif
73     static_assert(std::alignment_of<T1>::value == 32, "");
74     static_assert(sizeof(T1) == 32, "");
75     }
76     {
77     typedef std::aligned_storage<40, 32 >::type T1;
78 #if TEST_STD_VER > 11
79     static_assert(std::is_same<std::aligned_storage_t<40, 32>, T1>::value, "" );
80 #endif
81     static_assert(std::alignment_of<T1>::value == 32, "");
82     static_assert(sizeof(T1) == 64, "");
83     }
84     {
85     typedef std::aligned_storage<12, 16 >::type T1;
86 #if TEST_STD_VER > 11
87     static_assert(std::is_same<std::aligned_storage_t<12, 16>, T1>::value, "" );
88 #endif
89     static_assert(std::alignment_of<T1>::value == 16, "");
90     static_assert(sizeof(T1) == 16, "");
91     }
92     {
93     typedef std::aligned_storage<1>::type T1;
94 #if TEST_STD_VER > 11
95     static_assert(std::is_same<std::aligned_storage_t<1>, T1>::value, "" );
96 #endif
97     static_assert(std::alignment_of<T1>::value == 1, "");
98     static_assert(sizeof(T1) == 1, "");
99     }
100     {
101     typedef std::aligned_storage<2>::type T1;
102 #if TEST_STD_VER > 11
103     static_assert(std::is_same<std::aligned_storage_t<2>, T1>::value, "" );
104 #endif
105     static_assert(std::alignment_of<T1>::value == 2, "");
106     static_assert(sizeof(T1) == 2, "");
107     }
108     {
109     typedef std::aligned_storage<3>::type T1;
110 #if TEST_STD_VER > 11
111     static_assert(std::is_same<std::aligned_storage_t<3>, T1>::value, "" );
112 #endif
113     static_assert(std::alignment_of<T1>::value == 2, "");
114     static_assert(sizeof(T1) == 4, "");
115     }
116     {
117     typedef std::aligned_storage<4>::type T1;
118 #if TEST_STD_VER > 11
119     static_assert(std::is_same<std::aligned_storage_t<4>, T1>::value, "" );
120 #endif
121     static_assert(std::alignment_of<T1>::value == 4, "");
122     static_assert(sizeof(T1) == 4, "");
123     }
124     {
125     typedef std::aligned_storage<5>::type T1;
126 #if TEST_STD_VER > 11
127     static_assert(std::is_same<std::aligned_storage_t<5>, T1>::value, "" );
128 #endif
129     static_assert(std::alignment_of<T1>::value == 4, "");
130     static_assert(sizeof(T1) == 8, "");
131     }
132     {
133     typedef std::aligned_storage<7>::type T1;
134 #if TEST_STD_VER > 11
135     static_assert(std::is_same<std::aligned_storage_t<7>, T1>::value, "" );
136 #endif
137     static_assert(std::alignment_of<T1>::value == 4, "");
138     static_assert(sizeof(T1) == 8, "");
139     }
140     {
141     typedef std::aligned_storage<8>::type T1;
142 #if TEST_STD_VER > 11
143     static_assert(std::is_same<std::aligned_storage_t<8>, T1>::value, "" );
144 #endif
145     static_assert(std::alignment_of<T1>::value == 8, "");
146     static_assert(sizeof(T1) == 8, "");
147     }
148     {
149     typedef std::aligned_storage<9>::type T1;
150 #if TEST_STD_VER > 11
151     static_assert(std::is_same<std::aligned_storage_t<9>, T1>::value, "" );
152 #endif
153     static_assert(std::alignment_of<T1>::value == 8, "");
154     static_assert(sizeof(T1) == 16, "");
155     }
156     {
157     typedef std::aligned_storage<15>::type T1;
158 #if TEST_STD_VER > 11
159     static_assert(std::is_same<std::aligned_storage_t<15>, T1>::value, "" );
160 #endif
161     static_assert(std::alignment_of<T1>::value == 8, "");
162     static_assert(sizeof(T1) == 16, "");
163     }
164     // Use alignof(std::max_align_t) below to find the max alignment instead of
165     // hardcoding it, because it's different on different platforms.
166     // (For example 8 on arm and 16 on x86.)
167 #if TEST_STD_VER < 11
168 #define alignof __alignof__
169 #endif
170     {
171     typedef std::aligned_storage<16>::type T1;
172 #if TEST_STD_VER > 11
173     static_assert(std::is_same<std::aligned_storage_t<16>, T1>::value, "" );
174 #endif
175     static_assert(std::alignment_of<T1>::value == alignof(std::max_align_t),
176                   "");
177     static_assert(sizeof(T1) == 16, "");
178     }
179     {
180     typedef std::aligned_storage<17>::type T1;
181 #if TEST_STD_VER > 11
182     static_assert(std::is_same<std::aligned_storage_t<17>, T1>::value, "" );
183 #endif
184     static_assert(std::alignment_of<T1>::value == alignof(std::max_align_t),
185                   "");
186     static_assert(sizeof(T1) == 16 + alignof(std::max_align_t), "");
187     }
188     {
189     typedef std::aligned_storage<10>::type T1;
190 #if TEST_STD_VER > 11
191     static_assert(std::is_same<std::aligned_storage_t<10>, T1>::value, "" );
192 #endif
193     static_assert(std::alignment_of<T1>::value == 8, "");
194     static_assert(sizeof(T1) == 16, "");
195     }
196 }
197