Somehow aligned_union got dropped through the cracks.  This adds it.  Did a drive-by fix of alignment_of while I was in the neighborhood.

llvm-svn: 180036
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 20428e94e0b59b3bbfbafbdde7b461cf19f65dd0
diff --git a/include/type_traits b/include/type_traits
index 7178978..ab0e222 100644
--- a/include/type_traits
+++ b/include/type_traits
@@ -129,6 +129,7 @@
     template <class T> struct alignment_of;
     template <size_t Len, size_t Align = most_stringent_alignment_requirement>
         struct aligned_storage;
+    template <size_t Len, class... Types> struct aligned_union;
 
     template <class T> struct decay;
     template <class... T> struct common_type;
@@ -828,10 +829,8 @@
 
 // alignment_of
 
-template <class _Tp> struct __alignment_of {_Tp __lx;};
-
 template <class _Tp> struct _LIBCPP_TYPE_VIS alignment_of
-    : public integral_constant<size_t, __alignof__(__alignment_of<typename remove_all_extents<_Tp>::type>)> {};
+    : public integral_constant<size_t, __alignof__(_Tp)> {};
 
 // aligned_storage
 
@@ -960,6 +959,38 @@
 
 #undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
 
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+// aligned_union
+
+template <size_t _I0, size_t ..._In>
+struct __static_max;
+
+template <size_t _I0>
+struct __static_max<_I0>
+{
+    static const size_t value = _I0;
+};
+
+template <size_t _I0, size_t _I1, size_t ..._In>
+struct __static_max<_I0, _I1, _In...>
+{
+    static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
+                                             __static_max<_I1, _In...>::value;
+};
+
+template <size_t _Len, class _Type0, class ..._Types>
+struct aligned_union
+{
+    static const size_t alignment_value = __static_max<__alignof__(_Type0),
+                                                       __alignof__(_Types)...>::value;
+    static const size_t __len = __static_max<_Len, sizeof(_Type0),
+                                             sizeof(_Types)...>::value;
+    typedef typename aligned_storage<__len, alignment_value>::type type;
+};
+
+#endif  // _LIBCPP_HAS_NO_VARIADICS
+
 // __promote
 
 template <class _A1, class _A2 = void, class _A3 = void,
diff --git a/test/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp b/test/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp
index 845c762..323fd5e 100644
--- a/test/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp
+++ b/test/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp
@@ -92,17 +92,17 @@
     }
     {
     typedef std::aligned_storage<8>::type T1;
-    static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), "");
+    static_assert(std::alignment_of<T1>::value == 8, "");
     static_assert(sizeof(T1) == 8, "");
     }
     {
     typedef std::aligned_storage<9>::type T1;
-    static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), "");
-    static_assert(sizeof(T1) == (sizeof(long) == 4 ? 12 : 16), "");
+    static_assert(std::alignment_of<T1>::value == 8, "");
+    static_assert(sizeof(T1) == 16, "");
     }
     {
     typedef std::aligned_storage<15>::type T1;
-    static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), "");
+    static_assert(std::alignment_of<T1>::value == 8, "");
     static_assert(sizeof(T1) == 16, "");
     }
     {
@@ -117,7 +117,7 @@
     }
     {
     typedef std::aligned_storage<10>::type T1;
-    static_assert(std::alignment_of<T1>::value == (sizeof(long) == 4 ? 4 : 8), "");
-    static_assert(sizeof(T1) == (sizeof(long) == 4 ? 12 : 16), "");
+    static_assert(std::alignment_of<T1>::value == 8, "");
+    static_assert(sizeof(T1) == 16, "");
     }
 }
diff --git a/test/utilities/meta/meta.trans/meta.trans.other/aligned_union.pass.cpp b/test/utilities/meta/meta.trans/meta.trans.other/aligned_union.pass.cpp
new file mode 100644
index 0000000..b07a064
--- /dev/null
+++ b/test/utilities/meta/meta.trans/meta.trans.other/aligned_union.pass.cpp
@@ -0,0 +1,65 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// type_traits
+
+// aligned_union<size_t Len, class ...Types>
+
+#include <type_traits>
+
+int main()
+{
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+    {
+    typedef std::aligned_union<10, char >::type T1;
+    static_assert(std::alignment_of<T1>::value == 1, "");
+    static_assert(sizeof(T1) == 10, "");
+    }
+    {
+    typedef std::aligned_union<10, short >::type T1;
+    static_assert(std::alignment_of<T1>::value == 2, "");
+    static_assert(sizeof(T1) == 10, "");
+    }
+    {
+    typedef std::aligned_union<10, int >::type T1;
+    static_assert(std::alignment_of<T1>::value == 4, "");
+    static_assert(sizeof(T1) == 12, "");
+    }
+    {
+    typedef std::aligned_union<10, double >::type T1;
+    static_assert(std::alignment_of<T1>::value == 8, "");
+    static_assert(sizeof(T1) == 16, "");
+    }
+    {
+    typedef std::aligned_union<10, short, char >::type T1;
+    static_assert(std::alignment_of<T1>::value == 2, "");
+    static_assert(sizeof(T1) == 10, "");
+    }
+    {
+    typedef std::aligned_union<10, char, short >::type T1;
+    static_assert(std::alignment_of<T1>::value == 2, "");
+    static_assert(sizeof(T1) == 10, "");
+    }
+    {
+    typedef std::aligned_union<2, int, char, short >::type T1;
+    static_assert(std::alignment_of<T1>::value == 4, "");
+    static_assert(sizeof(T1) == 4, "");
+    }
+    {
+    typedef std::aligned_union<2, char, int, short >::type T1;
+    static_assert(std::alignment_of<T1>::value == 4, "");
+    static_assert(sizeof(T1) == 4, "");
+    }
+    {
+    typedef std::aligned_union<2, char, short, int >::type T1;
+    static_assert(std::alignment_of<T1>::value == 4, "");
+    static_assert(sizeof(T1) == 4, "");
+    }
+#endif
+}
diff --git a/test/utilities/meta/meta.unary.prop.query/alignment_of.pass.cpp b/test/utilities/meta/meta.unary.prop.query/alignment_of.pass.cpp
index 87c2224..c896aa2 100644
--- a/test/utilities/meta/meta.unary.prop.query/alignment_of.pass.cpp
+++ b/test/utilities/meta/meta.unary.prop.query/alignment_of.pass.cpp
@@ -30,13 +30,13 @@
 
 int main()
 {
-    test_alignment_of<int&, sizeof(long) == 4 ? 4 : 8>();
+    test_alignment_of<int&, 4>();
     test_alignment_of<Class, 1>();
     test_alignment_of<int*, sizeof(long) == 4 ? 4 : 8>();
     test_alignment_of<const int*, sizeof(long) == 4 ? 4 : 8>();
     test_alignment_of<char[3], 1>();
     test_alignment_of<int, 4>();
-    test_alignment_of<double, sizeof(long) == 4 ? 4 : 8>();
+    test_alignment_of<double, 8>();
     test_alignment_of<bool, 1>();
     test_alignment_of<unsigned, 4>();
 }