1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // type_traits
10
11 // aligned_union<size_t Len, class ...Types>
12
13 // Issue 3034 added:
14 // The member typedef type shall be a trivial standard-layout type.
15
16 #include <type_traits>
17
18 #include "test_macros.h"
19
main(int,char **)20 int main(int, char**)
21 {
22 {
23 typedef std::aligned_union<10, char >::type T1;
24 #if TEST_STD_VER > 11
25 ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, char>);
26 #endif
27 static_assert(std::is_trivial<T1>::value, "");
28 static_assert(std::is_standard_layout<T1>::value, "");
29 static_assert(std::alignment_of<T1>::value == 1, "");
30 static_assert(sizeof(T1) == 10, "");
31 }
32 {
33 typedef std::aligned_union<10, short >::type T1;
34 #if TEST_STD_VER > 11
35 ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, short>);
36 #endif
37 static_assert(std::is_trivial<T1>::value, "");
38 static_assert(std::is_standard_layout<T1>::value, "");
39 static_assert(std::alignment_of<T1>::value == 2, "");
40 static_assert(sizeof(T1) == 10, "");
41 }
42 {
43 typedef std::aligned_union<10, int >::type T1;
44 #if TEST_STD_VER > 11
45 ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, int>);
46 #endif
47 static_assert(std::is_trivial<T1>::value, "");
48 static_assert(std::is_standard_layout<T1>::value, "");
49 static_assert(std::alignment_of<T1>::value == 4, "");
50 static_assert(sizeof(T1) == 12, "");
51 }
52 {
53 typedef std::aligned_union<10, double >::type T1;
54 #if TEST_STD_VER > 11
55 ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, double>);
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 == 8, "");
60 static_assert(sizeof(T1) == 16, "");
61 }
62 {
63 typedef std::aligned_union<10, short, char >::type T1;
64 #if TEST_STD_VER > 11
65 ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, short, char>);
66 #endif
67 static_assert(std::is_trivial<T1>::value, "");
68 static_assert(std::is_standard_layout<T1>::value, "");
69 static_assert(std::alignment_of<T1>::value == 2, "");
70 static_assert(sizeof(T1) == 10, "");
71 }
72 {
73 typedef std::aligned_union<10, char, short >::type T1;
74 #if TEST_STD_VER > 11
75 ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, char, short>);
76 #endif
77 static_assert(std::is_trivial<T1>::value, "");
78 static_assert(std::is_standard_layout<T1>::value, "");
79 static_assert(std::alignment_of<T1>::value == 2, "");
80 static_assert(sizeof(T1) == 10, "");
81 }
82 {
83 typedef std::aligned_union<2, int, char, short >::type T1;
84 #if TEST_STD_VER > 11
85 ASSERT_SAME_TYPE(T1, std::aligned_union_t<2, int, char, short>);
86 #endif
87 static_assert(std::is_trivial<T1>::value, "");
88 static_assert(std::is_standard_layout<T1>::value, "");
89 static_assert(std::alignment_of<T1>::value == 4, "");
90 static_assert(sizeof(T1) == 4, "");
91 }
92 {
93 typedef std::aligned_union<2, char, int, short >::type T1;
94 #if TEST_STD_VER > 11
95 ASSERT_SAME_TYPE(T1, std::aligned_union_t<2, char, int, short>);
96 #endif
97 static_assert(std::is_trivial<T1>::value, "");
98 static_assert(std::is_standard_layout<T1>::value, "");
99 static_assert(std::alignment_of<T1>::value == 4, "");
100 static_assert(sizeof(T1) == 4, "");
101 }
102 {
103 typedef std::aligned_union<2, char, short, int >::type T1;
104 #if TEST_STD_VER > 11
105 ASSERT_SAME_TYPE(T1, std::aligned_union_t<2, char, short, int>);
106 #endif
107 static_assert(std::is_trivial<T1>::value, "");
108 static_assert(std::is_standard_layout<T1>::value, "");
109 static_assert(std::alignment_of<T1>::value == 4, "");
110 static_assert(sizeof(T1) == 4, "");
111 }
112
113 return 0;
114 }
115