Skip to content

Commit

Permalink
[libc++] Prefer __has_builtin for detecting compiler-provided type_tr…
Browse files Browse the repository at this point in the history
…aits

Both clang and GCC support using `__has_builtin` for detecting compiler-provided type_traits. Use it instead of `__has_keyword` or `__has_feature` to remove special-casing for GCC-provided builtins

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D129056
  • Loading branch information
philnik777 committed Jul 6, 2022
1 parent 30b6c51 commit 2040fde
Show file tree
Hide file tree
Showing 28 changed files with 71 additions and 71 deletions.
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/extent.h
Expand Up @@ -19,7 +19,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_keyword(__array_extent)
#if __has_builtin(__array_extent)

template<class _Tp, size_t _Dim = 0>
struct _LIBCPP_TEMPLATE_VIS extent
Expand All @@ -30,7 +30,7 @@ template <class _Tp, unsigned _Ip = 0>
inline constexpr size_t extent_v = __array_extent(_Tp, _Ip);
#endif

#else // __has_keyword(__array_extent)
#else // __has_builtin(__array_extent)

template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TEMPLATE_VIS extent
: public integral_constant<size_t, 0> {};
Expand All @@ -48,7 +48,7 @@ template <class _Tp, unsigned _Ip = 0>
inline constexpr size_t extent_v = extent<_Tp, _Ip>::value;
#endif

#endif // __has_keyword(__array_extent)
#endif // __has_builtin(__array_extent)

_LIBCPP_END_NAMESPACE_STD

Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__type_traits/has_virtual_destructor.h
Expand Up @@ -18,7 +18,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_feature(has_virtual_destructor) || defined(_LIBCPP_COMPILER_GCC)
#if __has_builtin(__has_virtual_destructor)

template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
: public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__type_traits/is_array.h
Expand Up @@ -21,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD

// TODO: Clang incorrectly reports that __is_array is true for T[0].
// Re-enable the branch once https://llvm.org/PR54705 is fixed.
#if __has_keyword(__is_array) && 0
#if __has_builtin(__is_array) && 0

template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_array : _BoolConstant<__is_array(_Tp)> { };
Expand All @@ -45,7 +45,7 @@ template <class _Tp>
inline constexpr bool is_array_v = is_array<_Tp>::value;
#endif

#endif // __has_keyword(__is_array)
#endif // __has_builtin(__is_array)

_LIBCPP_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/is_assignable.h
Expand Up @@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD

template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG _Tp type; };

#if __has_keyword(__is_assignable)
#if __has_builtin(__is_assignable)

template<class _Tp, class _Up>
struct _LIBCPP_TEMPLATE_VIS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> { };
Expand All @@ -30,7 +30,7 @@ template <class _Tp, class _Arg>
inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Arg);
#endif

#else // __has_keyword(__is_assignable)
#else // __has_builtin(__is_assignable)

template <class _Tp, class _Arg>
typename __select_2nd<decltype((declval<_Tp>() = declval<_Arg>())), true_type>::type
Expand Down Expand Up @@ -59,7 +59,7 @@ template <class _Tp, class _Arg>
inline constexpr bool is_assignable_v = is_assignable<_Tp, _Arg>::value;
#endif

#endif // __has_keyword(__is_assignable)
#endif // __has_builtin(__is_assignable)

_LIBCPP_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/is_compound.h
Expand Up @@ -19,7 +19,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_keyword(__is_compound)
#if __has_builtin(__is_compound)

template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_compound : _BoolConstant<__is_compound(_Tp)> { };
Expand All @@ -29,7 +29,7 @@ template <class _Tp>
inline constexpr bool is_compound_v = __is_compound(_Tp);
#endif

#else // __has_keyword(__is_compound)
#else // __has_builtin(__is_compound)

template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_compound
: public integral_constant<bool, !is_fundamental<_Tp>::value> {};
Expand All @@ -39,7 +39,7 @@ template <class _Tp>
inline constexpr bool is_compound_v = is_compound<_Tp>::value;
#endif

#endif // __has_keyword(__is_compound)
#endif // __has_builtin(__is_compound)

_LIBCPP_END_NAMESPACE_STD

Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__type_traits/is_const.h
Expand Up @@ -18,7 +18,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_keyword(__is_const)
#if __has_builtin(__is_const)

template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_const : _BoolConstant<__is_const(_Tp)> { };
Expand All @@ -38,7 +38,7 @@ template <class _Tp>
inline constexpr bool is_const_v = is_const<_Tp>::value;
#endif

#endif // __has_keyword(__is_const)
#endif // __has_builtin(__is_const)

_LIBCPP_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/is_convertible.h
Expand Up @@ -24,12 +24,12 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
#if __has_builtin(__is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)

template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
: public integral_constant<bool, __is_convertible_to(_T1, _T2)> {};

#else // __has_feature(is_convertible_to)
#else // __has_builtin(__is_convertible_to)

namespace __is_convertible_imp
{
Expand Down Expand Up @@ -96,7 +96,7 @@ template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
};

#endif // __has_feature(is_convertible_to)
#endif // __has_builtin(__is_convertible_to)

#if _LIBCPP_STD_VER > 14
template <class _From, class _To>
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/is_destructible.h
Expand Up @@ -22,7 +22,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_keyword(__is_destructible)
#if __has_builtin(__is_destructible)

template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_destructible : _BoolConstant<__is_destructible(_Tp)> { };
Expand All @@ -32,7 +32,7 @@ template <class _Tp>
inline constexpr bool is_destructible_v = __is_destructible(_Tp);
#endif

#else // __has_keyword(__is_destructible)
#else // __has_builtin(__is_destructible)

// if it's a reference, return true
// if it's a function, return false
Expand Down Expand Up @@ -95,7 +95,7 @@ template <class _Tp>
inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
#endif

#endif // __has_keyword(__is_destructible)
#endif // __has_builtin(__is_destructible)

_LIBCPP_END_NAMESPACE_STD

Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__type_traits/is_function.h
Expand Up @@ -20,7 +20,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_keyword(__is_function)
#if __has_builtin(__is_function)

template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_function : integral_constant<bool, __is_function(_Tp)> {};
Expand All @@ -31,7 +31,7 @@ template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_function
: public integral_constant<bool, !(is_reference<_Tp>::value || is_const<const _Tp>::value)> {};

#endif // __has_keyword(__is_function)
#endif // __has_builtin(__is_function)

#if _LIBCPP_STD_VER > 14
template <class _Tp>
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/is_fundamental.h
Expand Up @@ -20,7 +20,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_keyword(__is_fundamental)
#if __has_builtin(__is_fundamental)

template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { };
Expand All @@ -30,7 +30,7 @@ template <class _Tp>
inline constexpr bool is_fundamental_v = __is_fundamental(_Tp);
#endif

#else // __has_keyword(__is_fundamental)
#else // __has_builtin(__is_fundamental)

template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_fundamental
: public integral_constant<bool, is_void<_Tp>::value ||
Expand All @@ -42,7 +42,7 @@ template <class _Tp>
inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value;
#endif

#endif // __has_keyword(__is_fundamental)
#endif // __has_builtin(__is_fundamental)

_LIBCPP_END_NAMESPACE_STD

Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__type_traits/is_integral.h
Expand Up @@ -45,7 +45,7 @@ template <> struct __libcpp_is_integral<__int128_t> { enum { va
template <> struct __libcpp_is_integral<__uint128_t> { enum { value = 1 }; };
#endif

#if __has_keyword(__is_integral)
#if __has_builtin(__is_integral)

template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_integral : _BoolConstant<__is_integral(_Tp)> { };
Expand All @@ -65,7 +65,7 @@ template <class _Tp>
inline constexpr bool is_integral_v = is_integral<_Tp>::value;
#endif

#endif // __has_keyword(__is_integral)
#endif // __has_builtin(__is_integral)

_LIBCPP_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/is_member_function_pointer.h
Expand Up @@ -36,7 +36,7 @@ template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> {
};
};

#if __has_keyword(__is_member_function_pointer)
#if __has_builtin(__is_member_function_pointer)

template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
Expand All @@ -47,7 +47,7 @@ template <class _Tp>
inline constexpr bool is_member_function_pointer_v = __is_member_function_pointer(_Tp);
#endif

#else // __has_keyword(__is_member_function_pointer)
#else // __has_builtin(__is_member_function_pointer)

template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
: public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_func > {};
Expand All @@ -57,7 +57,7 @@ template <class _Tp>
inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<_Tp>::value;
#endif

#endif // __has_keyword(__is_member_function_pointer)
#endif // __has_builtin(__is_member_function_pointer)

_LIBCPP_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/is_member_object_pointer.h
Expand Up @@ -18,7 +18,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_keyword(__is_member_object_pointer)
#if __has_builtin(__is_member_object_pointer)

template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
Expand All @@ -29,7 +29,7 @@ template <class _Tp>
inline constexpr bool is_member_object_pointer_v = __is_member_object_pointer(_Tp);
#endif

#else // __has_keyword(__is_member_object_pointer)
#else // __has_builtin(__is_member_object_pointer)

template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
: public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_obj > {};
Expand All @@ -39,7 +39,7 @@ template <class _Tp>
inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<_Tp>::value;
#endif

#endif // __has_keyword(__is_member_object_pointer)
#endif // __has_builtin(__is_member_object_pointer)

_LIBCPP_END_NAMESPACE_STD

Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/is_member_pointer.h
Expand Up @@ -18,7 +18,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_keyword(__is_member_pointer)
#if __has_builtin(__is_member_pointer)

template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> { };
Expand All @@ -28,7 +28,7 @@ template <class _Tp>
inline constexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
#endif

#else // __has_keyword(__is_member_pointer)
#else // __has_builtin(__is_member_pointer)

template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer
: public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_member > {};
Expand All @@ -38,7 +38,7 @@ template <class _Tp>
inline constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value;
#endif

#endif // __has_keyword(__is_member_pointer)
#endif // __has_builtin(__is_member_pointer)

_LIBCPP_END_NAMESPACE_STD

Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__type_traits/is_nothrow_assignable.h
Expand Up @@ -19,7 +19,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_keyword(__is_nothrow_assignable)
#if __has_builtin(__is_nothrow_assignable)

template <class _Tp, class _Arg>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
Expand Down Expand Up @@ -47,7 +47,7 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
{
};

#endif // _LIBCPP_HAS_NO_NOEXCEPT
#endif // __has_builtin(__is_nothrow_assignable)

#if _LIBCPP_STD_VER > 14
template <class _Tp, class _Arg>
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__type_traits/is_nothrow_constructible.h
Expand Up @@ -19,7 +19,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_keyword(__is_nothrow_constructible)
#if __has_builtin(__is_nothrow_constructible)

template <class _Tp, class... _Args>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
Expand Down Expand Up @@ -62,7 +62,7 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
{
};

#endif // _LIBCPP_HAS_NO_NOEXCEPT
#endif // __has_builtin(__is_nothrow_constructible)


#if _LIBCPP_STD_VER > 14
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__type_traits/is_object.h
Expand Up @@ -22,7 +22,7 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_keyword(__is_object)
#if __has_builtin(__is_object)

template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_object : _BoolConstant<__is_object(_Tp)> { };
Expand All @@ -32,7 +32,7 @@ template <class _Tp>
inline constexpr bool is_object_v = __is_object(_Tp);
#endif

#else // __has_keyword(__is_object)
#else // __has_builtin(__is_object)

template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_object
: public integral_constant<bool, is_scalar<_Tp>::value ||
Expand All @@ -45,7 +45,7 @@ template <class _Tp>
inline constexpr bool is_object_v = is_object<_Tp>::value;
#endif

#endif // __has_keyword(__is_object)
#endif // __has_builtin(__is_object)

_LIBCPP_END_NAMESPACE_STD

Expand Down

0 comments on commit 2040fde

Please sign in to comment.