brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.7 KiB · 943a3f6 Raw
126 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS10 11// type_traits12 13// aligned_union<size_t Len, class ...Types>14 15//  Issue 3034 added:16//  The member typedef type shall be a trivial standard-layout type.17 18#include <type_traits>19 20#include "test_macros.h"21 22int main(int, char**)23{24    {25    typedef std::aligned_union<10, char >::type T1;26#if TEST_STD_VER > 1127    ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, char>);28#endif29    static_assert(std::is_trivially_copyable<T1>::value, "");30    static_assert(std::is_trivially_default_constructible<T1>::value, "");31    static_assert(std::is_standard_layout<T1>::value, "");32    static_assert(std::alignment_of<T1>::value == 1, "");33    static_assert(sizeof(T1) == 10, "");34    }35    {36    typedef std::aligned_union<10, short >::type T1;37#if TEST_STD_VER > 1138    ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, short>);39#endif40    static_assert(std::is_trivially_copyable<T1>::value, "");41    static_assert(std::is_trivially_default_constructible<T1>::value, "");42    static_assert(std::is_standard_layout<T1>::value, "");43    static_assert(std::alignment_of<T1>::value == 2, "");44    static_assert(sizeof(T1) == 10, "");45    }46    {47    typedef std::aligned_union<10, int >::type T1;48#if TEST_STD_VER > 1149    ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, int>);50#endif51    static_assert(std::is_trivially_copyable<T1>::value, "");52    static_assert(std::is_trivially_default_constructible<T1>::value, "");53    static_assert(std::is_standard_layout<T1>::value, "");54    static_assert(std::alignment_of<T1>::value == 4, "");55    static_assert(sizeof(T1) == 12, "");56    }57    {58    typedef std::aligned_union<10, double >::type T1;59#if TEST_STD_VER > 1160    ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, double>);61#endif62    static_assert(std::is_trivially_copyable<T1>::value, "");63    static_assert(std::is_trivially_default_constructible<T1>::value, "");64    static_assert(std::is_standard_layout<T1>::value, "");65    static_assert(std::alignment_of<T1>::value == 8, "");66    static_assert(sizeof(T1) == 16, "");67    }68    {69    typedef std::aligned_union<10, short, char >::type T1;70#if TEST_STD_VER > 1171    ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, short, char>);72#endif73    static_assert(std::is_trivially_copyable<T1>::value, "");74    static_assert(std::is_trivially_default_constructible<T1>::value, "");75    static_assert(std::is_standard_layout<T1>::value, "");76    static_assert(std::alignment_of<T1>::value == 2, "");77    static_assert(sizeof(T1) == 10, "");78    }79    {80    typedef std::aligned_union<10, char, short >::type T1;81#if TEST_STD_VER > 1182    ASSERT_SAME_TYPE(T1, std::aligned_union_t<10, char, short>);83#endif84    static_assert(std::is_trivially_copyable<T1>::value, "");85    static_assert(std::is_trivially_default_constructible<T1>::value, "");86    static_assert(std::is_standard_layout<T1>::value, "");87    static_assert(std::alignment_of<T1>::value == 2, "");88    static_assert(sizeof(T1) == 10, "");89    }90    {91    typedef std::aligned_union<2, int, char, short >::type T1;92#if TEST_STD_VER > 1193    ASSERT_SAME_TYPE(T1, std::aligned_union_t<2, int, char, short>);94#endif95    static_assert(std::is_trivially_copyable<T1>::value, "");96    static_assert(std::is_trivially_default_constructible<T1>::value, "");97    static_assert(std::is_standard_layout<T1>::value, "");98    static_assert(std::alignment_of<T1>::value == 4, "");99    static_assert(sizeof(T1) == 4, "");100    }101    {102    typedef std::aligned_union<2, char, int, short >::type T1;103#if TEST_STD_VER > 11104    ASSERT_SAME_TYPE(T1, std::aligned_union_t<2, char, int, short>);105#endif106    static_assert(std::is_trivially_copyable<T1>::value, "");107    static_assert(std::is_trivially_default_constructible<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    typedef std::aligned_union<2, char, short, int >::type T1;114#if TEST_STD_VER > 11115    ASSERT_SAME_TYPE(T1, std::aligned_union_t<2, char, short, int>);116#endif117    static_assert(std::is_trivially_copyable<T1>::value, "");118    static_assert(std::is_trivially_default_constructible<T1>::value, "");119    static_assert(std::is_standard_layout<T1>::value, "");120    static_assert(std::alignment_of<T1>::value == 4, "");121    static_assert(sizeof(T1) == 4, "");122    }123 124  return 0;125}126