1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
13 // aligned_union<size_t Len, class ...Types>
16 // The member typedef type shall be a trivial standard-layout type.
18 #include <type_traits>
20 #include "test_macros.h"
25 typedef std::aligned_union
<10, char >::type T1
;
27 ASSERT_SAME_TYPE(T1
, std::aligned_union_t
<10, char>);
29 static_assert(std::is_trivial
<T1
>::value
, "");
30 static_assert(std::is_standard_layout
<T1
>::value
, "");
31 static_assert(std::alignment_of
<T1
>::value
== 1, "");
32 static_assert(sizeof(T1
) == 10, "");
35 typedef std::aligned_union
<10, short >::type T1
;
37 ASSERT_SAME_TYPE(T1
, std::aligned_union_t
<10, short>);
39 static_assert(std::is_trivial
<T1
>::value
, "");
40 static_assert(std::is_standard_layout
<T1
>::value
, "");
41 static_assert(std::alignment_of
<T1
>::value
== 2, "");
42 static_assert(sizeof(T1
) == 10, "");
45 typedef std::aligned_union
<10, int >::type T1
;
47 ASSERT_SAME_TYPE(T1
, std::aligned_union_t
<10, int>);
49 static_assert(std::is_trivial
<T1
>::value
, "");
50 static_assert(std::is_standard_layout
<T1
>::value
, "");
51 static_assert(std::alignment_of
<T1
>::value
== 4, "");
52 static_assert(sizeof(T1
) == 12, "");
55 typedef std::aligned_union
<10, double >::type T1
;
57 ASSERT_SAME_TYPE(T1
, std::aligned_union_t
<10, double>);
59 static_assert(std::is_trivial
<T1
>::value
, "");
60 static_assert(std::is_standard_layout
<T1
>::value
, "");
61 static_assert(std::alignment_of
<T1
>::value
== 8, "");
62 static_assert(sizeof(T1
) == 16, "");
65 typedef std::aligned_union
<10, short, char >::type T1
;
67 ASSERT_SAME_TYPE(T1
, std::aligned_union_t
<10, short, char>);
69 static_assert(std::is_trivial
<T1
>::value
, "");
70 static_assert(std::is_standard_layout
<T1
>::value
, "");
71 static_assert(std::alignment_of
<T1
>::value
== 2, "");
72 static_assert(sizeof(T1
) == 10, "");
75 typedef std::aligned_union
<10, char, short >::type T1
;
77 ASSERT_SAME_TYPE(T1
, std::aligned_union_t
<10, char, short>);
79 static_assert(std::is_trivial
<T1
>::value
, "");
80 static_assert(std::is_standard_layout
<T1
>::value
, "");
81 static_assert(std::alignment_of
<T1
>::value
== 2, "");
82 static_assert(sizeof(T1
) == 10, "");
85 typedef std::aligned_union
<2, int, char, short >::type T1
;
87 ASSERT_SAME_TYPE(T1
, std::aligned_union_t
<2, int, char, short>);
89 static_assert(std::is_trivial
<T1
>::value
, "");
90 static_assert(std::is_standard_layout
<T1
>::value
, "");
91 static_assert(std::alignment_of
<T1
>::value
== 4, "");
92 static_assert(sizeof(T1
) == 4, "");
95 typedef std::aligned_union
<2, char, int, short >::type T1
;
97 ASSERT_SAME_TYPE(T1
, std::aligned_union_t
<2, char, int, short>);
99 static_assert(std::is_trivial
<T1
>::value
, "");
100 static_assert(std::is_standard_layout
<T1
>::value
, "");
101 static_assert(std::alignment_of
<T1
>::value
== 4, "");
102 static_assert(sizeof(T1
) == 4, "");
105 typedef std::aligned_union
<2, char, short, int >::type T1
;
106 #if TEST_STD_VER > 11
107 ASSERT_SAME_TYPE(T1
, std::aligned_union_t
<2, char, short, int>);
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
== 4, "");
112 static_assert(sizeof(T1
) == 4, "");