From: Nikolas Klauser Date: Sun, 26 Jun 2022 12:55:19 +0000 (+0200) Subject: [libc++] Simplify type_traits and use more builtins X-Git-Tag: upstream/15.0.7~3528 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=31ae52859f7a2339f31bb78c5163c23cb872f179;p=platform%2Fupstream%2Fllvm.git [libc++] Simplify type_traits and use more builtins Reviewed By: ldionne, #libc Spies: manojgupta, cjdb, ayzhao, alanphipps, libcxx-commits Differential Revision: https://reviews.llvm.org/D127226 Stuff --- diff --git a/libcxx/include/__type_traits/is_abstract.h b/libcxx/include/__type_traits/is_abstract.h index 0480118..c74b328 100644 --- a/libcxx/include/__type_traits/is_abstract.h +++ b/libcxx/include/__type_traits/is_abstract.h @@ -23,7 +23,7 @@ template struct _LIBCPP_TEMPLATE_VIS is_abstract #if _LIBCPP_STD_VER > 14 template -inline constexpr bool is_abstract_v = is_abstract<_Tp>::value; +inline constexpr bool is_abstract_v = __is_abstract(_Tp); #endif _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__type_traits/is_aggregate.h b/libcxx/include/__type_traits/is_aggregate.h index f32aec8..ea9de84 100644 --- a/libcxx/include/__type_traits/is_aggregate.h +++ b/libcxx/include/__type_traits/is_aggregate.h @@ -24,7 +24,7 @@ template struct _LIBCPP_TEMPLATE_VIS is_aggregate : public integral_constant {}; template -inline constexpr bool is_aggregate_v = is_aggregate<_Tp>::value; +inline constexpr bool is_aggregate_v = __is_aggregate(_Tp); #endif // _LIBCPP_STD_VER > 14 diff --git a/libcxx/include/__type_traits/is_base_of.h b/libcxx/include/__type_traits/is_base_of.h index b944a65..0e6dec0 100644 --- a/libcxx/include/__type_traits/is_base_of.h +++ b/libcxx/include/__type_traits/is_base_of.h @@ -24,7 +24,7 @@ struct _LIBCPP_TEMPLATE_VIS is_base_of #if _LIBCPP_STD_VER > 14 template -inline constexpr bool is_base_of_v = is_base_of<_Bp, _Dp>::value; +inline constexpr bool is_base_of_v = __is_base_of(_Bp, _Dp); #endif _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__type_traits/is_class.h b/libcxx/include/__type_traits/is_class.h index 8e07a5e..cddaeae 100644 --- a/libcxx/include/__type_traits/is_class.h +++ b/libcxx/include/__type_traits/is_class.h @@ -20,27 +20,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if __has_feature(is_class) || defined(_LIBCPP_COMPILER_GCC) - template struct _LIBCPP_TEMPLATE_VIS is_class : public integral_constant {}; -#else - -namespace __is_class_imp -{ -template true_type __test(int _Tp::*); -template false_type __test(...); -} - -template struct _LIBCPP_TEMPLATE_VIS is_class - : public integral_constant(0))::value && !is_union<_Tp>::value> {}; - -#endif - #if _LIBCPP_STD_VER > 14 template -inline constexpr bool is_class_v = is_class<_Tp>::value; +inline constexpr bool is_class_v = __is_class(_Tp); #endif _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__type_traits/is_compound.h b/libcxx/include/__type_traits/is_compound.h index f055155..643edd7 100644 --- a/libcxx/include/__type_traits/is_compound.h +++ b/libcxx/include/__type_traits/is_compound.h @@ -19,8 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -// >= 11 because in C++03 nullptr isn't actually nullptr -#if __has_keyword(__is_compound) && !defined(_LIBCPP_CXX03_LANG) +#if __has_keyword(__is_compound) template struct _LIBCPP_TEMPLATE_VIS is_compound : _BoolConstant<__is_compound(_Tp)> { }; diff --git a/libcxx/include/__type_traits/is_empty.h b/libcxx/include/__type_traits/is_empty.h index e81c6f7..042b4e6 100644 --- a/libcxx/include/__type_traits/is_empty.h +++ b/libcxx/include/__type_traits/is_empty.h @@ -18,38 +18,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if __has_feature(is_empty) || defined(_LIBCPP_COMPILER_GCC) - template struct _LIBCPP_TEMPLATE_VIS is_empty : public integral_constant {}; -#else // __has_feature(is_empty) - -template -struct __is_empty1 - : public _Tp -{ - double __lx; -}; - -struct __is_empty2 -{ - double __lx; -}; - -template ::value> -struct __libcpp_empty : public integral_constant) == sizeof(__is_empty2)> {}; - -template struct __libcpp_empty<_Tp, false> : public false_type {}; - -template struct _LIBCPP_TEMPLATE_VIS is_empty : public __libcpp_empty<_Tp> {}; - -#endif // __has_feature(is_empty) - #if _LIBCPP_STD_VER > 14 template -inline constexpr bool is_empty_v = is_empty<_Tp>::value; +inline constexpr bool is_empty_v = __is_empty(_Tp); #endif _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__type_traits/is_enum.h b/libcxx/include/__type_traits/is_enum.h index ac160da..bf6921c 100644 --- a/libcxx/include/__type_traits/is_enum.h +++ b/libcxx/include/__type_traits/is_enum.h @@ -19,8 +19,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC) - template struct _LIBCPP_TEMPLATE_VIS is_enum : public integral_constant {}; @@ -29,27 +27,6 @@ template inline constexpr bool is_enum_v = __is_enum(_Tp); #endif -#else - -template struct _LIBCPP_TEMPLATE_VIS is_enum - : public integral_constant::value && - !is_integral<_Tp>::value && - !is_floating_point<_Tp>::value && - !is_array<_Tp>::value && - !is_pointer<_Tp>::value && - !is_reference<_Tp>::value && - !is_member_pointer<_Tp>::value && - !is_union<_Tp>::value && - !is_class<_Tp>::value && - !is_function<_Tp>::value > {}; - -#if _LIBCPP_STD_VER > 14 -template -inline constexpr bool is_enum_v = is_enum<_Tp>::value; -#endif - -#endif // __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC) - _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___TYPE_TRAITS_IS_ENUM_H diff --git a/libcxx/include/__type_traits/is_final.h b/libcxx/include/__type_traits/is_final.h index f2d9b5b..74ced23 100644 --- a/libcxx/include/__type_traits/is_final.h +++ b/libcxx/include/__type_traits/is_final.h @@ -28,7 +28,7 @@ is_final : public integral_constant {}; #if _LIBCPP_STD_VER > 14 template -inline constexpr bool is_final_v = is_final<_Tp>::value; +inline constexpr bool is_final_v = __is_final(_Tp); #endif _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__type_traits/is_function.h b/libcxx/include/__type_traits/is_function.h index 23ba9cb..bce980c 100644 --- a/libcxx/include/__type_traits/is_function.h +++ b/libcxx/include/__type_traits/is_function.h @@ -20,15 +20,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template struct _LIBCPP_TEMPLATE_VIS is_function - : public _BoolConstant< -#ifdef __clang__ - __is_function(_Tp) +#if __has_keyword(__is_function) + +template +struct _LIBCPP_TEMPLATE_VIS is_function : integral_constant {}; + #else - !(is_reference<_Tp>::value || is_const::value) -#endif - > {}; +template +struct _LIBCPP_TEMPLATE_VIS is_function + : public integral_constant::value || is_const::value)> {}; + +#endif // __has_keyword(__is_function) #if _LIBCPP_STD_VER > 14 template diff --git a/libcxx/include/__type_traits/is_fundamental.h b/libcxx/include/__type_traits/is_fundamental.h index 859cfde..aaa7063 100644 --- a/libcxx/include/__type_traits/is_fundamental.h +++ b/libcxx/include/__type_traits/is_fundamental.h @@ -20,11 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -// Before Clang 10, __is_fundamental didn't work for nullptr_t. -// In C++03 nullptr_t is library-provided but must still count as "fundamental." -#if __has_keyword(__is_fundamental) && \ - !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1000) && \ - !defined(_LIBCPP_CXX03_LANG) +#if __has_keyword(__is_fundamental) template struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { }; diff --git a/libcxx/include/__type_traits/is_pointer.h b/libcxx/include/__type_traits/is_pointer.h index ab66989..2139b03 100644 --- a/libcxx/include/__type_traits/is_pointer.h +++ b/libcxx/include/__type_traits/is_pointer.h @@ -19,9 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -// Before AppleClang 12.0.5, __is_pointer didn't work for Objective-C types. -#if __has_keyword(__is_pointer) && \ - !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1205) +#if __has_keyword(__is_pointer) template struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { }; diff --git a/libcxx/include/__type_traits/is_scalar.h b/libcxx/include/__type_traits/is_scalar.h index f745bf5..0ca34c7 100644 --- a/libcxx/include/__type_traits/is_scalar.h +++ b/libcxx/include/__type_traits/is_scalar.h @@ -22,8 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -// In C++03 nullptr_t is library-provided but must still count as "scalar." -#if __has_keyword(__is_scalar) && !defined(_LIBCPP_CXX03_LANG) +#if __has_keyword(__is_scalar) template struct _LIBCPP_TEMPLATE_VIS is_scalar : _BoolConstant<__is_scalar(_Tp)> { }; diff --git a/libcxx/include/__type_traits/is_union.h b/libcxx/include/__type_traits/is_union.h index d02931f..3e8cffe 100644 --- a/libcxx/include/__type_traits/is_union.h +++ b/libcxx/include/__type_traits/is_union.h @@ -19,22 +19,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if __has_feature(is_union) || defined(_LIBCPP_COMPILER_GCC) - template struct _LIBCPP_TEMPLATE_VIS is_union : public integral_constant {}; -#else - -template struct __libcpp_union : public false_type {}; -template struct _LIBCPP_TEMPLATE_VIS is_union - : public __libcpp_union::type> {}; - -#endif - #if _LIBCPP_STD_VER > 14 template -inline constexpr bool is_union_v = is_union<_Tp>::value; +inline constexpr bool is_union_v = __is_union(_Tp); #endif _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__type_traits/is_unsigned.h b/libcxx/include/__type_traits/is_unsigned.h index b052281..bb279fd 100644 --- a/libcxx/include/__type_traits/is_unsigned.h +++ b/libcxx/include/__type_traits/is_unsigned.h @@ -20,11 +20,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD -// Before Clang 13, __is_unsigned returned true for enums with signed underlying type. -// No currently-released version of AppleClang contains the fixed intrinsic. -#if __has_keyword(__is_unsigned) && \ - !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1300) && \ - !defined(_LIBCPP_APPLE_CLANG_VER) +// Before AppleClang 14, __is_unsigned returned true for enums with signed underlying type. +#if __has_keyword(__is_unsigned) && !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1400) template struct _LIBCPP_TEMPLATE_VIS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> { };