diff options
author | Howard Hinnant <hhinnant@apple.com> | 2012-02-24 23:32:26 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2012-02-24 23:32:26 +0000 |
commit | 8d01935c099a03837461808e0d772fa5ac681a10 (patch) | |
tree | 3c1f2435d63471b5ead93b6f1eff04348cd2e776 | |
parent | 5e1148e31dd57bbb29dd40041a556434fc76fb84 (diff) | |
download | bcm5719-llvm-8d01935c099a03837461808e0d772fa5ac681a10.tar.gz bcm5719-llvm-8d01935c099a03837461808e0d772fa5ac681a10.zip |
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.
llvm-svn: 151406
3 files changed, 77 insertions, 55 deletions
diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits index ee8877cfc60..13129f31d66 100644 --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -2219,6 +2219,16 @@ struct _LIBCPP_VISIBLE is_move_constructible #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> struct _LIBCPP_VISIBLE is_trivially_constructible : false_type @@ -2241,34 +2251,24 @@ struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&&> #else struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp> #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> -#endif { }; template <class _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> -#endif { }; template <class _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> -#endif { }; +#endif // !__has_feature(is_trivially_constructible) + #else // _LIBCPP_HAS_NO_VARIADICS 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> +struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, __is_construct::__nat, + __is_construct::__nat> + : integral_constant<bool, __is_trivially_constructible(_Tp)> +{ +}; + +template <class _Tp> +struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp, + __is_construct::__nat> + : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp)> +{ +}; + +template <class _Tp> +struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&, + __is_construct::__nat> + : integral_constant<bool, __is_trivially_constructible(_Tp, const _Tp&)> +{ +}; + +template <class _Tp> +struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&, + __is_construct::__nat> + : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp&)> +{ +}; + +#else // !__has_feature(is_trivially_constructible) + template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, __is_construct::__nat, __is_construct::__nat> -#if __has_feature(has_trivial_constructor) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) - : integral_constant<bool, __has_trivial_constructor(_Tp)> -#else : integral_constant<bool, is_scalar<_Tp>::value> -#endif { }; template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp, __is_construct::__nat> -#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> -#endif { }; template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, const _Tp&, __is_construct::__nat> -#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> -#endif { }; template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_constructible<_Tp, _Tp&, __is_construct::__nat> -#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> -#endif { }; +#endif // !__has_feature(is_trivially_constructible) + #endif // _LIBCPP_HAS_NO_VARIADICS // is_trivially_default_constructible @@ -2348,46 +2366,42 @@ template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_move_constructible // 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> struct is_trivially_assignable : public false_type {}; template <class _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> {}; -#endif template <class _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> {}; -#endif template <class _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> {}; -#endif #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _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> {}; -#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // !__has_feature(is_trivially_constructible) + // is_trivially_copy_assignable template <class _Tp> struct _LIBCPP_VISIBLE is_trivially_copy_assignable diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copy_constructible.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copy_constructible.pass.cpp index 45f63622f85..6bd78ec9e7a 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copy_constructible.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_copy_constructible.pass.cpp @@ -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<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> @@ -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<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 diff --git a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_move_constructible.pass.cpp b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_move_constructible.pass.cpp index a4fcbcb09c5..54cb5e853a8 100644 --- a/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_move_constructible.pass.cpp +++ b/libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_move_constructible.pass.cpp @@ -17,18 +17,12 @@ template <class T> void test_is_trivially_move_constructible() { 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> void test_has_not_trivial_move_constructor() { 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 @@ -59,6 +53,20 @@ struct A A(const A&); }; +#if __has_feature(cxx_defaulted_functions) + +struct MoveOnly1 +{ + MoveOnly1(MoveOnly1&&); +}; + +struct MoveOnly2 +{ + MoveOnly2(MoveOnly2&&) = default; +}; + +#endif + int main() { 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<NotEmpty>(); - test_is_trivially_move_constructible<int&>(); test_is_trivially_move_constructible<Union>(); test_is_trivially_move_constructible<Empty>(); test_is_trivially_move_constructible<int>(); @@ -74,4 +81,9 @@ int main() test_is_trivially_move_constructible<int*>(); test_is_trivially_move_constructible<const int*>(); 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 } |