[libcxx-commits] [libcxx] r359159 - Use modern type trait implementations when available.
Richard Smith via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Apr 24 17:35:01 PDT 2019
Author: rsmith
Date: Wed Apr 24 17:35:01 2019
New Revision: 359159
URL: http://llvm.org/viewvc/llvm-project?rev=359159&view=rev
Log:
Use modern type trait implementations when available.
Teach libcxx to stop using various deprecated __has_* type traits, in favor of
the ("modern", C++11 era) __is_* type traits.
This is mostly just a simplification, but fixes at least one bug: _Atomic T
should be considered trivially-destructible, but is not considered to be POD by
Clang, and __has_trivial_destructor is specified in the GCC documentation as
returning false for non-POD non-class types.
Differential Revision: https://reviews.llvm.org/D48292
Modified:
libcxx/trunk/include/type_traits
libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp
Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=359159&r1=359158&r2=359159&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Wed Apr 24 17:35:01 2019
@@ -3729,7 +3729,12 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR boo
// is_trivially_destructible
-#if __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403)
+#if __has_keyword(__is_trivially_destructible)
+
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
+ : public integral_constant<bool, __is_trivially_destructible(_Tp)> {};
+
+#elif __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403)
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
: public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
@@ -3756,18 +3761,15 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR boo
// is_nothrow_constructible
-#if 0
-template <class _Tp, class... _Args>
-struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
- : public integral_constant<bool, __is_nothrow_constructible(_Tp(_Args...))>
-{
-};
+#ifndef _LIBCPP_HAS_NO_VARIADICS
-#else
+#if __has_keyword(__is_nothrow_constructible)
-#ifndef _LIBCPP_HAS_NO_VARIADICS
+template <class _Tp, class... _Args>
+struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
+ : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
-#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
+#elif __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
@@ -3804,7 +3806,7 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_c
{
};
-#else // __has_feature(cxx_noexcept)
+#else // __has_keyword(__is_nothrow_constructible) || __has_feature(cxx_noexcept)
template <class _Tp, class... _Args>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
@@ -3860,6 +3862,23 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_c
#else // _LIBCPP_HAS_NO_VARIADICS
+#if __has_keyword(__is_nothrow_constructible)
+
+template <class _Tp, class _A0 = __is_construct::__nat,
+ class _A1 = __is_construct::__nat>
+struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
+ : public integral_constant<bool, __is_nothrow_constructible(_Tp, _A0, _A1)> {};
+
+template <class _Tp, class _A0>
+struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _A0>
+ : public integral_constant<bool, __is_nothrow_constructible(_Tp, _A0)> {};
+
+template <class _Tp>
+struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp>
+ : public integral_constant<bool, __is_nothrow_constructible(_Tp)> {};
+
+#else // __has_keyword(__is_nothrow_constructible)
+
template <class _Tp, class _A0 = __is_construct::__nat,
class _A1 = __is_construct::__nat>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
@@ -3911,8 +3930,8 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_c
{
};
+#endif // __has_keyword(__is_nothrow_constructible)
#endif // _LIBCPP_HAS_NO_VARIADICS
-#endif // __has_feature(is_nothrow_constructible)
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
template <class _Tp, class ..._Args>
@@ -3962,7 +3981,13 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR boo
// is_nothrow_assignable
-#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
+#if __has_keyword(__is_nothrow_assignable)
+
+template <class _Tp, class _Arg>
+struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
+ : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};
+
+#elif __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
@@ -3984,7 +4009,7 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_a
{
};
-#else // __has_feature(cxx_noexcept)
+#else // __has_keyword(__is_nothrow_assignable) || __has_feature(cxx_noexcept)
template <class _Tp, class _Arg>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
Modified: libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp?rev=359159&r1=359158&r2=359159&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_trivially_destructible.pass.cpp Wed Apr 24 17:35:01 2019
@@ -116,5 +116,11 @@ int main(int, char**)
test_is_not_trivially_destructible<PurePrivateDestructor>();
#endif
+#if TEST_HAS_BUILTIN_IDENTIFIER(_Atomic)
+ test_is_trivially_destructible<_Atomic int>();
+ test_is_trivially_destructible<_Atomic float>();
+ test_is_trivially_destructible<_Atomic int*>();
+#endif
+
return 0;
}
More information about the libcxx-commits
mailing list