aligned_storage.pass.cpp (10118B)
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 // Issue 3034 added: 15 // The member typedef type shall be a trivial standard-layout type. 16 17 #include <type_traits> 18 #include <cstddef> // for std::max_align_t 19 #include "test_macros.h" 20 21 int main() 22 { 23 { 24 typedef std::aligned_storage<10, 1 >::type T1; 25 #if TEST_STD_VER > 11 26 static_assert(std::is_same<std::aligned_storage_t<10, 1>, T1>::value, ""); 27 #endif 28 #if TEST_STD_VER <= 17 29 static_assert(std::is_pod<T1>::value, ""); 30 #endif 31 static_assert(std::is_trivial<T1>::value, ""); 32 static_assert(std::is_standard_layout<T1>::value, ""); 33 static_assert(std::alignment_of<T1>::value == 1, ""); 34 static_assert(sizeof(T1) == 10, ""); 35 } 36 { 37 typedef std::aligned_storage<10, 2 >::type T1; 38 #if TEST_STD_VER > 11 39 static_assert(std::is_same<std::aligned_storage_t<10, 2>, T1>::value, ""); 40 #endif 41 #if TEST_STD_VER <= 17 42 static_assert(std::is_pod<T1>::value, ""); 43 #endif 44 static_assert(std::is_trivial<T1>::value, ""); 45 static_assert(std::is_standard_layout<T1>::value, ""); 46 static_assert(std::alignment_of<T1>::value == 2, ""); 47 static_assert(sizeof(T1) == 10, ""); 48 } 49 { 50 typedef std::aligned_storage<10, 4 >::type T1; 51 #if TEST_STD_VER > 11 52 static_assert(std::is_same<std::aligned_storage_t<10, 4>, T1>::value, ""); 53 #endif 54 #if TEST_STD_VER <= 17 55 static_assert(std::is_pod<T1>::value, ""); 56 #endif 57 static_assert(std::is_trivial<T1>::value, ""); 58 static_assert(std::is_standard_layout<T1>::value, ""); 59 static_assert(std::alignment_of<T1>::value == 4, ""); 60 static_assert(sizeof(T1) == 12, ""); 61 } 62 { 63 typedef std::aligned_storage<10, 8 >::type T1; 64 #if TEST_STD_VER > 11 65 static_assert(std::is_same<std::aligned_storage_t<10, 8>, T1>::value, ""); 66 #endif 67 #if TEST_STD_VER <= 17 68 static_assert(std::is_pod<T1>::value, ""); 69 #endif 70 static_assert(std::is_trivial<T1>::value, ""); 71 static_assert(std::is_standard_layout<T1>::value, ""); 72 static_assert(std::alignment_of<T1>::value == 8, ""); 73 static_assert(sizeof(T1) == 16, ""); 74 } 75 { 76 typedef std::aligned_storage<10, 16 >::type T1; 77 #if TEST_STD_VER > 11 78 static_assert(std::is_same<std::aligned_storage_t<10, 16>, T1>::value, ""); 79 #endif 80 #if TEST_STD_VER <= 17 81 static_assert(std::is_pod<T1>::value, ""); 82 #endif 83 static_assert(std::is_trivial<T1>::value, ""); 84 static_assert(std::is_standard_layout<T1>::value, ""); 85 static_assert(std::alignment_of<T1>::value == 16, ""); 86 static_assert(sizeof(T1) == 16, ""); 87 } 88 { 89 typedef std::aligned_storage<10, 32 >::type T1; 90 #if TEST_STD_VER > 11 91 static_assert(std::is_same<std::aligned_storage_t<10, 32>, T1>::value, ""); 92 #endif 93 #if TEST_STD_VER <= 17 94 static_assert(std::is_pod<T1>::value, ""); 95 #endif 96 static_assert(std::is_trivial<T1>::value, ""); 97 static_assert(std::is_standard_layout<T1>::value, ""); 98 static_assert(std::alignment_of<T1>::value == 32, ""); 99 static_assert(sizeof(T1) == 32, ""); 100 } 101 { 102 typedef std::aligned_storage<20, 32 >::type T1; 103 #if TEST_STD_VER > 11 104 static_assert(std::is_same<std::aligned_storage_t<20, 32>, T1>::value, ""); 105 #endif 106 #if TEST_STD_VER <= 17 107 static_assert(std::is_pod<T1>::value, ""); 108 #endif 109 static_assert(std::is_trivial<T1>::value, ""); 110 static_assert(std::is_standard_layout<T1>::value, ""); 111 static_assert(std::alignment_of<T1>::value == 32, ""); 112 static_assert(sizeof(T1) == 32, ""); 113 } 114 { 115 typedef std::aligned_storage<40, 32 >::type T1; 116 #if TEST_STD_VER > 11 117 static_assert(std::is_same<std::aligned_storage_t<40, 32>, T1>::value, ""); 118 #endif 119 #if TEST_STD_VER <= 17 120 static_assert(std::is_pod<T1>::value, ""); 121 #endif 122 static_assert(std::is_trivial<T1>::value, ""); 123 static_assert(std::is_standard_layout<T1>::value, ""); 124 static_assert(std::alignment_of<T1>::value == 32, ""); 125 static_assert(sizeof(T1) == 64, ""); 126 } 127 { 128 typedef std::aligned_storage<12, 16 >::type T1; 129 #if TEST_STD_VER > 11 130 static_assert(std::is_same<std::aligned_storage_t<12, 16>, T1>::value, ""); 131 #endif 132 #if TEST_STD_VER <= 17 133 static_assert(std::is_pod<T1>::value, ""); 134 #endif 135 static_assert(std::is_trivial<T1>::value, ""); 136 static_assert(std::is_standard_layout<T1>::value, ""); 137 static_assert(std::alignment_of<T1>::value == 16, ""); 138 static_assert(sizeof(T1) == 16, ""); 139 } 140 { 141 typedef std::aligned_storage<1>::type T1; 142 #if TEST_STD_VER > 11 143 static_assert(std::is_same<std::aligned_storage_t<1>, T1>::value, ""); 144 #endif 145 #if TEST_STD_VER <= 17 146 static_assert(std::is_pod<T1>::value, ""); 147 #endif 148 static_assert(std::is_trivial<T1>::value, ""); 149 static_assert(std::is_standard_layout<T1>::value, ""); 150 static_assert(std::alignment_of<T1>::value == 1, ""); 151 static_assert(sizeof(T1) == 1, ""); 152 } 153 { 154 typedef std::aligned_storage<2>::type T1; 155 #if TEST_STD_VER > 11 156 static_assert(std::is_same<std::aligned_storage_t<2>, T1>::value, ""); 157 #endif 158 #if TEST_STD_VER <= 17 159 static_assert(std::is_pod<T1>::value, ""); 160 #endif 161 static_assert(std::is_trivial<T1>::value, ""); 162 static_assert(std::is_standard_layout<T1>::value, ""); 163 static_assert(std::alignment_of<T1>::value == 2, ""); 164 static_assert(sizeof(T1) == 2, ""); 165 } 166 { 167 typedef std::aligned_storage<3>::type T1; 168 #if TEST_STD_VER > 11 169 static_assert(std::is_same<std::aligned_storage_t<3>, T1>::value, ""); 170 #endif 171 #if TEST_STD_VER <= 17 172 static_assert(std::is_pod<T1>::value, ""); 173 #endif 174 static_assert(std::is_trivial<T1>::value, ""); 175 static_assert(std::is_standard_layout<T1>::value, ""); 176 static_assert(std::alignment_of<T1>::value == 2, ""); 177 static_assert(sizeof(T1) == 4, ""); 178 } 179 { 180 typedef std::aligned_storage<4>::type T1; 181 #if TEST_STD_VER > 11 182 static_assert(std::is_same<std::aligned_storage_t<4>, T1>::value, ""); 183 #endif 184 #if TEST_STD_VER <= 17 185 static_assert(std::is_pod<T1>::value, ""); 186 #endif 187 static_assert(std::is_trivial<T1>::value, ""); 188 static_assert(std::is_standard_layout<T1>::value, ""); 189 static_assert(std::alignment_of<T1>::value == 4, ""); 190 static_assert(sizeof(T1) == 4, ""); 191 } 192 { 193 typedef std::aligned_storage<5>::type T1; 194 #if TEST_STD_VER > 11 195 static_assert(std::is_same<std::aligned_storage_t<5>, T1>::value, ""); 196 #endif 197 #if TEST_STD_VER <= 17 198 static_assert(std::is_pod<T1>::value, ""); 199 #endif 200 static_assert(std::is_trivial<T1>::value, ""); 201 static_assert(std::is_standard_layout<T1>::value, ""); 202 static_assert(std::alignment_of<T1>::value == 4, ""); 203 static_assert(sizeof(T1) == 8, ""); 204 } 205 { 206 typedef std::aligned_storage<7>::type T1; 207 #if TEST_STD_VER > 11 208 static_assert(std::is_same<std::aligned_storage_t<7>, T1>::value, ""); 209 #endif 210 static_assert(std::is_trivial<T1>::value, ""); 211 static_assert(std::is_standard_layout<T1>::value, ""); 212 static_assert(std::alignment_of<T1>::value == 4, ""); 213 static_assert(sizeof(T1) == 8, ""); 214 } 215 { 216 typedef std::aligned_storage<8>::type T1; 217 #if TEST_STD_VER > 11 218 static_assert(std::is_same<std::aligned_storage_t<8>, T1>::value, ""); 219 #endif 220 #if TEST_STD_VER <= 17 221 static_assert(std::is_pod<T1>::value, ""); 222 #endif 223 static_assert(std::is_trivial<T1>::value, ""); 224 static_assert(std::is_standard_layout<T1>::value, ""); 225 static_assert(std::alignment_of<T1>::value == 8, ""); 226 static_assert(sizeof(T1) == 8, ""); 227 } 228 { 229 typedef std::aligned_storage<9>::type T1; 230 #if TEST_STD_VER > 11 231 static_assert(std::is_same<std::aligned_storage_t<9>, T1>::value, ""); 232 #endif 233 #if TEST_STD_VER <= 17 234 static_assert(std::is_pod<T1>::value, ""); 235 #endif 236 static_assert(std::is_trivial<T1>::value, ""); 237 static_assert(std::is_standard_layout<T1>::value, ""); 238 static_assert(std::alignment_of<T1>::value == 8, ""); 239 static_assert(sizeof(T1) == 16, ""); 240 } 241 { 242 typedef std::aligned_storage<15>::type T1; 243 #if TEST_STD_VER > 11 244 static_assert(std::is_same<std::aligned_storage_t<15>, T1>::value, ""); 245 #endif 246 #if TEST_STD_VER <= 17 247 static_assert(std::is_pod<T1>::value, ""); 248 #endif 249 static_assert(std::is_trivial<T1>::value, ""); 250 static_assert(std::is_standard_layout<T1>::value, ""); 251 static_assert(std::alignment_of<T1>::value == 8, ""); 252 static_assert(sizeof(T1) == 16, ""); 253 } 254 // Use alignof(std::max_align_t) below to find the max alignment instead of 255 // hardcoding it, because it's different on different platforms. 256 // (For example 8 on arm and 16 on x86.) 257 { 258 typedef std::aligned_storage<16>::type T1; 259 #if TEST_STD_VER > 11 260 static_assert(std::is_same<std::aligned_storage_t<16>, T1>::value, ""); 261 #endif 262 static_assert(std::is_trivial<T1>::value, ""); 263 static_assert(std::is_standard_layout<T1>::value, ""); 264 static_assert(std::alignment_of<T1>::value == TEST_ALIGNOF(std::max_align_t), 265 ""); 266 static_assert(sizeof(T1) == 16, ""); 267 } 268 { 269 typedef std::aligned_storage<17>::type T1; 270 #if TEST_STD_VER > 11 271 static_assert(std::is_same<std::aligned_storage_t<17>, T1>::value, ""); 272 #endif 273 static_assert(std::is_trivial<T1>::value, ""); 274 static_assert(std::is_standard_layout<T1>::value, ""); 275 static_assert(std::alignment_of<T1>::value == TEST_ALIGNOF(std::max_align_t), 276 ""); 277 static_assert(sizeof(T1) == 16 + TEST_ALIGNOF(std::max_align_t), ""); 278 } 279 { 280 typedef std::aligned_storage<10>::type T1; 281 #if TEST_STD_VER > 11 282 static_assert(std::is_same<std::aligned_storage_t<10>, T1>::value, ""); 283 #endif 284 static_assert(std::is_trivial<T1>::value, ""); 285 static_assert(std::is_standard_layout<T1>::value, ""); 286 static_assert(std::alignment_of<T1>::value == 8, ""); 287 static_assert(sizeof(T1) == 16, ""); 288 } 289 }