forked from OSchip/llvm-project
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
This commit is contained in:
parent
74679a93b2
commit
20428e94e0
|
@ -129,6 +129,7 @@ namespace std
|
|||
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 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS has_virtual_destructor
|
|||
|
||||
// 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 @@ _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
|
|||
|
||||
#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,
|
||||
|
|
|
@ -92,17 +92,17 @@ int main()
|
|||
}
|
||||
{
|
||||
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 @@ int main()
|
|||
}
|
||||
{
|
||||
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, "");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -30,13 +30,13 @@ public:
|
|||
|
||||
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>();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue