1c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant//===----------------------------------------------------------------------===// 2c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// 3c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// The LLVM Compiler Infrastructure 4c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// 5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// This file is dual licensed under the MIT and the University of Illinois Open 6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// Source Licenses. See LICENSE.TXT for details. 7c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// 8c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant//===----------------------------------------------------------------------===// 9c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant 10c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// type_traits 11c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant 12c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// aligned_storage 13c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant 14c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant#include <type_traits> 1555d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#include <cstddef> // for std::max_align_t 1655d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#include "test_macros.h" 17c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant 18c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnantint main() 19c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant{ 20c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 21c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<10, 1 >::type T1; 2255d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 23933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<10, 1>, T1>::value, "" ); 24933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 25c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 1, ""); 26c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 10, ""); 27c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 28c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 29c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<10, 2 >::type T1; 3055d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 31933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<10, 2>, T1>::value, "" ); 32933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 33c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 2, ""); 34c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 10, ""); 35c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 36c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 37c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<10, 4 >::type T1; 3855d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 39933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<10, 4>, T1>::value, "" ); 40933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 41c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 4, ""); 42c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 12, ""); 43c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 44c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 45c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<10, 8 >::type T1; 4655d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 47933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<10, 8>, T1>::value, "" ); 48933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 49c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 8, ""); 50c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 16, ""); 51c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 52c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 53c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<10, 16 >::type T1; 5455d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 55933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<10, 16>, T1>::value, "" ); 56933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 57c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 16, ""); 58c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 16, ""); 59c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 60c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 61c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<10, 32 >::type T1; 6255d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 63933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<10, 32>, T1>::value, "" ); 64933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 65c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 32, ""); 66c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 32, ""); 67c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 68c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 69c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<20, 32 >::type T1; 7055d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 71933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<20, 32>, T1>::value, "" ); 72933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 73c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 32, ""); 74c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 32, ""); 75c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 76c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 77c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<40, 32 >::type T1; 7855d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 79933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<40, 32>, T1>::value, "" ); 80933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 81c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 32, ""); 82c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 64, ""); 83c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 84c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 85c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<12, 16 >::type T1; 8655d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 87933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<12, 16>, T1>::value, "" ); 88933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 89c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 16, ""); 90c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 16, ""); 91c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 92c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 93c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<1>::type T1; 9455d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 95933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<1>, T1>::value, "" ); 96933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 97c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 1, ""); 98c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 1, ""); 99c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 100c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 101c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<2>::type T1; 10255d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 103933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<2>, T1>::value, "" ); 104933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 105c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 2, ""); 106c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 2, ""); 107c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 108c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 109c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<3>::type T1; 11055d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 111933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<3>, T1>::value, "" ); 112933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 113c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 2, ""); 114c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 4, ""); 115c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 116c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 117c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<4>::type T1; 11855d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 119933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<4>, T1>::value, "" ); 120933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 121c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 4, ""); 122c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 4, ""); 123c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 124c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 125c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<5>::type T1; 12655d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 127933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<5>, T1>::value, "" ); 128933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 129c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 4, ""); 130c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 8, ""); 131c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 132c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 133c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<7>::type T1; 13455d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 135933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<7>, T1>::value, "" ); 136933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 137c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(std::alignment_of<T1>::value == 4, ""); 138c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 8, ""); 139c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 140c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 141c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<8>::type T1; 14255d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 143933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<8>, T1>::value, "" ); 144933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 1455544f7e0c7c89c82acf8cf1f9681e737f3955755Howard Hinnant static_assert(std::alignment_of<T1>::value == 8, ""); 146c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 8, ""); 147c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 148c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 149c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<9>::type T1; 15055d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 151933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<9>, T1>::value, "" ); 152933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 1535544f7e0c7c89c82acf8cf1f9681e737f3955755Howard Hinnant static_assert(std::alignment_of<T1>::value == 8, ""); 1545544f7e0c7c89c82acf8cf1f9681e737f3955755Howard Hinnant static_assert(sizeof(T1) == 16, ""); 155c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 156c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 157c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<15>::type T1; 15855d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 159933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<15>, T1>::value, "" ); 160933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 1615544f7e0c7c89c82acf8cf1f9681e737f3955755Howard Hinnant static_assert(std::alignment_of<T1>::value == 8, ""); 162c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 16, ""); 163c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 164981b01d9d039fc21124345322d154fc0c30028e4Nico Weber // Use alignof(std::max_align_t) below to find the max alignment instead of 165981b01d9d039fc21124345322d154fc0c30028e4Nico Weber // hardcoding it, because it's different on different platforms. 166981b01d9d039fc21124345322d154fc0c30028e4Nico Weber // (For example 8 on arm and 16 on x86.) 167d24c465beaec2fe9a0e365e6379cd5d3acaeb2caEric Fiselier#if TEST_STD_VER < 11 168981b01d9d039fc21124345322d154fc0c30028e4Nico Weber#define alignof __alignof__ 169981b01d9d039fc21124345322d154fc0c30028e4Nico Weber#endif 170c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 171c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<16>::type T1; 17255d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 173933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<16>, T1>::value, "" ); 174933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 175981b01d9d039fc21124345322d154fc0c30028e4Nico Weber static_assert(std::alignment_of<T1>::value == alignof(std::max_align_t), 176981b01d9d039fc21124345322d154fc0c30028e4Nico Weber ""); 177c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant static_assert(sizeof(T1) == 16, ""); 178c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 179c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 180c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<17>::type T1; 18155d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 182933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<17>, T1>::value, "" ); 183933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 184981b01d9d039fc21124345322d154fc0c30028e4Nico Weber static_assert(std::alignment_of<T1>::value == alignof(std::max_align_t), 185981b01d9d039fc21124345322d154fc0c30028e4Nico Weber ""); 186981b01d9d039fc21124345322d154fc0c30028e4Nico Weber static_assert(sizeof(T1) == 16 + alignof(std::max_align_t), ""); 187c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 188c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 189c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant typedef std::aligned_storage<10>::type T1; 19055d741c32e72234c022c728f24ccafb80ab8b485Marshall Clow#if TEST_STD_VER > 11 191933afa9761c1c1f916161278a99284d50a594939Marshall Clow static_assert(std::is_same<std::aligned_storage_t<10>, T1>::value, "" ); 192933afa9761c1c1f916161278a99284d50a594939Marshall Clow#endif 1935544f7e0c7c89c82acf8cf1f9681e737f3955755Howard Hinnant static_assert(std::alignment_of<T1>::value == 8, ""); 1945544f7e0c7c89c82acf8cf1f9681e737f3955755Howard Hinnant static_assert(sizeof(T1) == 16, ""); 195c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 196c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant} 197