aligned_union.pass.cpp revision 5544f7e0c7c89c82acf8cf1f9681e737f3955755
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_union<size_t Len, class ...Types> 13 14#include <type_traits> 15 16int main() 17{ 18#ifndef _LIBCPP_HAS_NO_VARIADICS 19 { 20 typedef std::aligned_union<10, char >::type T1; 21 static_assert(std::alignment_of<T1>::value == 1, ""); 22 static_assert(sizeof(T1) == 10, ""); 23 } 24 { 25 typedef std::aligned_union<10, short >::type T1; 26 static_assert(std::alignment_of<T1>::value == 2, ""); 27 static_assert(sizeof(T1) == 10, ""); 28 } 29 { 30 typedef std::aligned_union<10, int >::type T1; 31 static_assert(std::alignment_of<T1>::value == 4, ""); 32 static_assert(sizeof(T1) == 12, ""); 33 } 34 { 35 typedef std::aligned_union<10, double >::type T1; 36 static_assert(std::alignment_of<T1>::value == 8, ""); 37 static_assert(sizeof(T1) == 16, ""); 38 } 39 { 40 typedef std::aligned_union<10, short, char >::type T1; 41 static_assert(std::alignment_of<T1>::value == 2, ""); 42 static_assert(sizeof(T1) == 10, ""); 43 } 44 { 45 typedef std::aligned_union<10, char, short >::type T1; 46 static_assert(std::alignment_of<T1>::value == 2, ""); 47 static_assert(sizeof(T1) == 10, ""); 48 } 49 { 50 typedef std::aligned_union<2, int, char, short >::type T1; 51 static_assert(std::alignment_of<T1>::value == 4, ""); 52 static_assert(sizeof(T1) == 4, ""); 53 } 54 { 55 typedef std::aligned_union<2, char, int, short >::type T1; 56 static_assert(std::alignment_of<T1>::value == 4, ""); 57 static_assert(sizeof(T1) == 4, ""); 58 } 59 { 60 typedef std::aligned_union<2, char, short, int >::type T1; 61 static_assert(std::alignment_of<T1>::value == 4, ""); 62 static_assert(sizeof(T1) == 4, ""); 63 } 64#endif 65} 66