Skip to content

Commit

Permalink
[libc] Use LIBC_HAS_BUILTIN instead of __has_builtin directly.
Browse files Browse the repository at this point in the history
Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D158313
  • Loading branch information
mikhailramalho committed Aug 21, 2023
1 parent db158c7 commit cd96aa7
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions libc/src/__support/CPP/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H

#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"

#include <stddef.h> // For size_t.

Expand Down Expand Up @@ -219,16 +220,17 @@ constexpr bool
declval<F>()))>> = true;

namespace details {
#if __has_builtin(__is_lvalue_reference) && \
__has_builtin(__is_rvalue_reference) && __has_builtin(__is_reference)
#if LIBC_HAS_BUILTIN(__is_lvalue_reference) && \
LIBC_HAS_BUILTIN(__is_rvalue_reference) && \
LIBC_HAS_BUILTIN(__is_reference)

template <typename T>
struct is_lvalue_reference : bool_constant<__is_lvalue_reference(T)> {};
template <typename T>
struct is_rvalue_reference : bool_constant<__is_rvalue_reference(T)> {};
template <typename T> struct is_reference : bool_constant<__is_reference(T)> {};

#else // __has_builtin(__is_lvalue_reference) && etc...
#else // LIBC_HAS_BUILTIN(__is_lvalue_reference) && etc...

template <typename T> struct is_lvalue_reference : public false_type {};
template <typename T> struct is_lvalue_reference<T &> : public true_type {};
Expand All @@ -240,9 +242,9 @@ template <typename T> struct is_reference : public false_type {};
template <typename T> struct is_reference<T &> : public true_type {};
template <typename T> struct is_reference<T &&> : public true_type {};

#endif // __has_builtin(__is_lvalue_reference) && etc...
#endif // LIBC_HAS_BUILTIN(__is_lvalue_reference) && etc...

#if __has_builtin(__remove_all_extents)
#if LIBC_HAS_BUILTIN(__remove_all_extents)
template <typename T> using __remove_all_extents_t = __remove_all_extents(T);
#else
template <typename T> struct remove_all_extents {
Expand All @@ -257,9 +259,9 @@ template <typename T, size_t _Np> struct remove_all_extents<T[_Np]> {

template <typename T>
using __remove_all_extents_t = typename remove_all_extents<T>::type;
#endif // __has_builtin(__remove_all_extents)
#endif // LIBC_HAS_BUILTIN(__remove_all_extents)

#if __has_builtin(__is_function)
#if LIBC_HAS_BUILTIN(__is_function)

template <typename T>
struct is_function : integral_constant<bool, __is_function(T)> {};
Expand All @@ -271,14 +273,14 @@ struct is_function
: public integral_constant<bool, !(is_reference<T>::value ||
is_const<const T>::value)> {};

#endif // __has_builtin(__is_function)
#endif // LIBC_HAS_BUILTIN(__is_function)

#if __has_builtin(__is_destructible)
#if LIBC_HAS_BUILTIN(__is_destructible)

template <typename T>
struct is_destructible : bool_constant<__is_destructible(T)> {};

#else // __has_builtin(__is_destructible)
#else // LIBC_HAS_BUILTIN(__is_destructible)

// if it's a reference, return true
// if it's a function, return false
Expand Down Expand Up @@ -324,24 +326,22 @@ struct is_destructible : public __destructible_false<T, is_function<T>::value> {
template <typename T> struct is_destructible<T[]> : public false_type {};
template <> struct is_destructible<void> : public false_type {};

#endif // __has_builtin(__is_destructible)
#endif // LIBC_HAS_BUILTIN(__is_destructible)
} // namespace details

#if __has_builtin(__is_trivially_destructible)
#if LIBC_HAS_BUILTIN(__is_trivially_destructible)

template <typename T>
struct is_trivially_destructible
: public integral_constant<bool, __is_trivially_destructible(T)> {};

#elif __has_builtin(__has_trivial_destructor)

#else
template <typename T>
struct is_trivially_destructible
: public integral_constant<
bool, __llvm_libc::cpp::details::is_destructible<T>::value
&&__has_trivial_destructor(T)> {};

#endif // __has_builtin(__is_trivially_destructible)
#endif // LIBC_HAS_BUILTIN(__is_trivially_destructible)

} // namespace cpp
} // namespace __llvm_libc
Expand Down

0 comments on commit cd96aa7

Please sign in to comment.