Hook up to the new clang __is_trivially_constructible and __is_trivially_assignable traits. Fixes r10925427 and http://llvm.org/bugs/show_bug.cgi?id=12038.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@151406 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2012-02-24 23:32:26 +00:00
parent b9344c218b
commit 4300839b5f
3 changed files with 81 additions and 59 deletions

View File

@ -2219,6 +2219,16 @@ struct _LIBCPP_VISIBLE is_move_constructible
#ifndef _LIBCPP_HAS_NO_VARIADICS #ifndef _LIBCPP_HAS_NO_VARIADICS
#if __has_feature(is_trivially_constructible)
template <class _Tp, class... _Args>
struct _LIBCPP_VISIBLE is_trivially_constructible
: integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
{
};
#else // !__has_feature(is_trivially_constructible)
template <class _Tp, class... _Args> template <class _Tp, class... _Args>
struct _LIBCPP_VISIBLE is_trivially_constructible struct _LIBCPP_VISIBLE is_trivially_constructible
: false_type : false_type
@ -2241,34 +2251,24 @@ struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&&>
#else #else
struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp> struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp>
#endif #endif
#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
: integral_constant<bool, __has_trivial_copy(_Tp)>
#else
: integral_constant<bool, is_scalar<_Tp>::value> : integral_constant<bool, is_scalar<_Tp>::value>
#endif
{ {
}; };
template <class _Tp> template <class _Tp>
struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&> struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&>
#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
: integral_constant<bool, __has_trivial_copy(_Tp)>
#else
: integral_constant<bool, is_scalar<_Tp>::value> : integral_constant<bool, is_scalar<_Tp>::value>
#endif
{ {
}; };
template <class _Tp> template <class _Tp>
struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&> struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&>
#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
: integral_constant<bool, __has_trivial_copy(_Tp)>
#else
: integral_constant<bool, is_scalar<_Tp>::value> : integral_constant<bool, is_scalar<_Tp>::value>
#endif
{ {
}; };
#endif // !__has_feature(is_trivially_constructible)
#else // _LIBCPP_HAS_NO_VARIADICS #else // _LIBCPP_HAS_NO_VARIADICS
template <class _Tp, class _A0 = __is_construct::__nat, template <class _Tp, class _A0 = __is_construct::__nat,
@ -2278,50 +2278,68 @@ struct _LIBCPP_VISIBLE is_trivially_constructible
{ {
}; };
#if __has_feature(is_trivially_constructible)
template <class _Tp> template <class _Tp>
struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, __is_construct::__nat, struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, __is_construct::__nat,
__is_construct::__nat> __is_construct::__nat>
#if __has_feature(has_trivial_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) : integral_constant<bool, __is_trivially_constructible(_Tp)>
: integral_constant<bool, __has_trivial_constructor(_Tp)>
#else
: integral_constant<bool, is_scalar<_Tp>::value>
#endif
{ {
}; };
template <class _Tp> template <class _Tp>
struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp, struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp,
__is_construct::__nat> __is_construct::__nat>
#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp)>
: integral_constant<bool, __has_trivial_copy(_Tp)>
#else
: integral_constant<bool, is_scalar<_Tp>::value>
#endif
{ {
}; };
template <class _Tp> template <class _Tp>
struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&, struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&,
__is_construct::__nat> __is_construct::__nat>
#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) : integral_constant<bool, __is_trivially_constructible(_Tp, const _Tp&)>
: integral_constant<bool, __has_trivial_copy(_Tp)>
#else
: integral_constant<bool, is_scalar<_Tp>::value>
#endif
{ {
}; };
template <class _Tp> template <class _Tp>
struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&, struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&,
__is_construct::__nat> __is_construct::__nat>
#if __has_feature(has_trivial_copy) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp&)>
: integral_constant<bool, __has_trivial_copy(_Tp)>
#else
: integral_constant<bool, is_scalar<_Tp>::value>
#endif
{ {
}; };
#else // !__has_feature(is_trivially_constructible)
template <class _Tp>
struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, __is_construct::__nat,
__is_construct::__nat>
: integral_constant<bool, is_scalar<_Tp>::value>
{
};
template <class _Tp>
struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp,
__is_construct::__nat>
: integral_constant<bool, is_scalar<_Tp>::value>
{
};
template <class _Tp>
struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&,
__is_construct::__nat>
: integral_constant<bool, is_scalar<_Tp>::value>
{
};
template <class _Tp>
struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&,
__is_construct::__nat>
: integral_constant<bool, is_scalar<_Tp>::value>
{
};
#endif // !__has_feature(is_trivially_constructible)
#endif // _LIBCPP_HAS_NO_VARIADICS #endif // _LIBCPP_HAS_NO_VARIADICS
// is_trivially_default_constructible // is_trivially_default_constructible
@ -2348,46 +2366,42 @@ template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_move_constructible
// is_trivially_assignable // is_trivially_assignable
#if __has_feature(is_trivially_constructible)
template <class _Tp, class _Arg>
struct is_trivially_assignable
: integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
{
};
#else // !__has_feature(is_trivially_constructible)
template <class _Tp, class _Arg> template <class _Tp, class _Arg>
struct is_trivially_assignable struct is_trivially_assignable
: public false_type {}; : public false_type {};
template <class _Tp> template <class _Tp>
struct is_trivially_assignable<_Tp&, _Tp> struct is_trivially_assignable<_Tp&, _Tp>
#if __has_feature(has_trivial_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
: integral_constant<bool, __has_trivial_assign(_Tp)> {};
#else
: integral_constant<bool, is_scalar<_Tp>::value> {}; : integral_constant<bool, is_scalar<_Tp>::value> {};
#endif
template <class _Tp> template <class _Tp>
struct is_trivially_assignable<_Tp&, _Tp&> struct is_trivially_assignable<_Tp&, _Tp&>
#if __has_feature(has_trivial_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
: integral_constant<bool, __has_trivial_assign(_Tp)> {};
#else
: integral_constant<bool, is_scalar<_Tp>::value> {}; : integral_constant<bool, is_scalar<_Tp>::value> {};
#endif
template <class _Tp> template <class _Tp>
struct is_trivially_assignable<_Tp&, const _Tp&> struct is_trivially_assignable<_Tp&, const _Tp&>
#if __has_feature(has_trivial_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
: integral_constant<bool, __has_trivial_assign(_Tp)> {};
#else
: integral_constant<bool, is_scalar<_Tp>::value> {}; : integral_constant<bool, is_scalar<_Tp>::value> {};
#endif
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Tp> template <class _Tp>
struct is_trivially_assignable<_Tp&, _Tp&&> struct is_trivially_assignable<_Tp&, _Tp&&>
#if __has_feature(has_trivial_assign) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
: integral_constant<bool, __has_trivial_assign(_Tp)> {};
#else
: integral_constant<bool, is_scalar<_Tp>::value> {}; : integral_constant<bool, is_scalar<_Tp>::value> {};
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif // !__has_feature(is_trivially_constructible)
// is_trivially_copy_assignable // is_trivially_copy_assignable
template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_copy_assignable template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_copy_assignable

View File

@ -18,8 +18,6 @@ void test_is_trivially_copy_constructible()
{ {
static_assert( std::is_trivially_copy_constructible<T>::value, ""); static_assert( std::is_trivially_copy_constructible<T>::value, "");
static_assert( std::is_trivially_copy_constructible<const T>::value, ""); static_assert( std::is_trivially_copy_constructible<const T>::value, "");
static_assert( std::is_trivially_copy_constructible<volatile T>::value, "");
static_assert( std::is_trivially_copy_constructible<const volatile T>::value, "");
} }
template <class T> template <class T>
@ -27,8 +25,6 @@ void test_has_not_trivial_copy_constructor()
{ {
static_assert(!std::is_trivially_copy_constructible<T>::value, ""); static_assert(!std::is_trivially_copy_constructible<T>::value, "");
static_assert(!std::is_trivially_copy_constructible<const T>::value, ""); static_assert(!std::is_trivially_copy_constructible<const T>::value, "");
static_assert(!std::is_trivially_copy_constructible<volatile T>::value, "");
static_assert(!std::is_trivially_copy_constructible<const volatile T>::value, "");
} }
class Empty class Empty

View File

@ -17,18 +17,12 @@ template <class T>
void test_is_trivially_move_constructible() void test_is_trivially_move_constructible()
{ {
static_assert( std::is_trivially_move_constructible<T>::value, ""); static_assert( std::is_trivially_move_constructible<T>::value, "");
static_assert( std::is_trivially_move_constructible<const T>::value, "");
static_assert( std::is_trivially_move_constructible<volatile T>::value, "");
static_assert( std::is_trivially_move_constructible<const volatile T>::value, "");
} }
template <class T> template <class T>
void test_has_not_trivial_move_constructor() void test_has_not_trivial_move_constructor()
{ {
static_assert(!std::is_trivially_move_constructible<T>::value, ""); static_assert(!std::is_trivially_move_constructible<T>::value, "");
static_assert(!std::is_trivially_move_constructible<const T>::value, "");
static_assert(!std::is_trivially_move_constructible<volatile T>::value, "");
static_assert(!std::is_trivially_move_constructible<const volatile T>::value, "");
} }
class Empty class Empty
@ -59,6 +53,20 @@ struct A
A(const A&); A(const A&);
}; };
#if __has_feature(cxx_defaulted_functions)
struct MoveOnly1
{
MoveOnly1(MoveOnly1&&);
};
struct MoveOnly2
{
MoveOnly2(MoveOnly2&&) = default;
};
#endif
int main() int main()
{ {
test_has_not_trivial_move_constructor<void>(); test_has_not_trivial_move_constructor<void>();
@ -66,7 +74,6 @@ int main()
test_has_not_trivial_move_constructor<Abstract>(); test_has_not_trivial_move_constructor<Abstract>();
test_has_not_trivial_move_constructor<NotEmpty>(); test_has_not_trivial_move_constructor<NotEmpty>();
test_is_trivially_move_constructible<int&>();
test_is_trivially_move_constructible<Union>(); test_is_trivially_move_constructible<Union>();
test_is_trivially_move_constructible<Empty>(); test_is_trivially_move_constructible<Empty>();
test_is_trivially_move_constructible<int>(); test_is_trivially_move_constructible<int>();
@ -74,4 +81,9 @@ int main()
test_is_trivially_move_constructible<int*>(); test_is_trivially_move_constructible<int*>();
test_is_trivially_move_constructible<const int*>(); test_is_trivially_move_constructible<const int*>();
test_is_trivially_move_constructible<bit_zero>(); test_is_trivially_move_constructible<bit_zero>();
#if __has_feature(cxx_defaulted_functions)
static_assert(!std::is_trivially_move_constructible<MoveOnly1>::value, "");
static_assert( std::is_trivially_move_constructible<MoveOnly2>::value, "");
#endif
} }