Commit cfe27e79 by Abseil Team Committed by Copybara-Service

Map the absl::is_trivially_* functions to their std impl

There's no point redefining these functions if they are supported by the compiler and the version of libstdc++. Also, some of the builtins used by the absl implementation of these functions (e.g. __has_trivial_destructor) have been deprecated in Clang 15.

PiperOrigin-RevId: 465554125
Change-Id: I8674c3a5270ce3c654cdf58ae7dbd9d2bda8faa5
parent c9736080
...@@ -273,6 +273,17 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || ...@@ -273,6 +273,17 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1 #define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1
#endif #endif
// ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE
//
// Checks whether `std::is_trivially_copyable<T>` is supported.
//
// Notes: Clang 15+ with libc++ supports these features, GCC hasn't been tested.
#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE)
#error ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE cannot be directly set
#elif defined(__clang__) && (__clang_major__ >= 15)
#define ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE 1
#endif
// ABSL_HAVE_THREAD_LOCAL // ABSL_HAVE_THREAD_LOCAL
// //
// Checks whether C++11's `thread_local` storage duration specifier is // Checks whether C++11's `thread_local` storage duration specifier is
......
...@@ -298,8 +298,12 @@ struct is_function ...@@ -298,8 +298,12 @@ struct is_function
// https://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html#Type-Traits. // https://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html#Type-Traits.
template <typename T> template <typename T>
struct is_trivially_destructible struct is_trivially_destructible
#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
: std::is_trivially_destructible<T> {
#else
: std::integral_constant<bool, __has_trivial_destructor(T) && : std::integral_constant<bool, __has_trivial_destructor(T) &&
std::is_destructible<T>::value> { std::is_destructible<T>::value> {
#endif
#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
private: private:
static constexpr bool compliant = std::is_trivially_destructible<T>::value == static constexpr bool compliant = std::is_trivially_destructible<T>::value ==
...@@ -347,9 +351,13 @@ struct is_trivially_destructible ...@@ -347,9 +351,13 @@ struct is_trivially_destructible
// Nontrivially destructible types will cause the expression to be nontrivial. // Nontrivially destructible types will cause the expression to be nontrivial.
template <typename T> template <typename T>
struct is_trivially_default_constructible struct is_trivially_default_constructible
#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
: std::is_trivially_default_constructible<T> {
#else
: std::integral_constant<bool, __has_trivial_constructor(T) && : std::integral_constant<bool, __has_trivial_constructor(T) &&
std::is_default_constructible<T>::value && std::is_default_constructible<T>::value &&
is_trivially_destructible<T>::value> { is_trivially_destructible<T>::value> {
#endif
#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \ #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \
!defined( \ !defined( \
ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION) ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION)
...@@ -381,10 +389,14 @@ struct is_trivially_default_constructible ...@@ -381,10 +389,14 @@ struct is_trivially_default_constructible
// expression to be nontrivial. // expression to be nontrivial.
template <typename T> template <typename T>
struct is_trivially_move_constructible struct is_trivially_move_constructible
#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
: std::is_trivially_move_constructible<T> {
#else
: std::conditional< : std::conditional<
std::is_object<T>::value && !std::is_array<T>::value, std::is_object<T>::value && !std::is_array<T>::value,
type_traits_internal::IsTriviallyMoveConstructibleObject<T>, type_traits_internal::IsTriviallyMoveConstructibleObject<T>,
std::is_reference<T>>::type::type { std::is_reference<T>>::type::type {
#endif
#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \ #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \
!defined( \ !defined( \
ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION) ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION)
...@@ -490,9 +502,13 @@ struct is_trivially_move_assignable ...@@ -490,9 +502,13 @@ struct is_trivially_move_assignable
// `is_trivially_assignable<T&, const T&>`. // `is_trivially_assignable<T&, const T&>`.
template <typename T> template <typename T>
struct is_trivially_copy_assignable struct is_trivially_copy_assignable
#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
: std::is_trivially_copy_assignable<T> {
#else
: std::integral_constant< : std::integral_constant<
bool, __has_trivial_assign(typename std::remove_reference<T>::type) && bool, __has_trivial_assign(typename std::remove_reference<T>::type) &&
absl::is_copy_assignable<T>::value> { absl::is_copy_assignable<T>::value> {
#endif
#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
private: private:
static constexpr bool compliant = static constexpr bool compliant =
...@@ -544,6 +560,11 @@ namespace type_traits_internal { ...@@ -544,6 +560,11 @@ namespace type_traits_internal {
// destructible. Arrays of trivially copyable types are trivially copyable. // destructible. Arrays of trivially copyable types are trivially copyable.
// //
// We expose this metafunction only for internal use within absl. // We expose this metafunction only for internal use within absl.
#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE)
template <typename T>
struct is_trivially_copyable : std::is_trivially_copyable<T> {};
#else
template <typename T> template <typename T>
class is_trivially_copyable_impl { class is_trivially_copyable_impl {
using ExtentsRemoved = typename std::remove_all_extents<T>::type; using ExtentsRemoved = typename std::remove_all_extents<T>::type;
...@@ -569,6 +590,7 @@ template <typename T> ...@@ -569,6 +590,7 @@ template <typename T>
struct is_trivially_copyable struct is_trivially_copyable
: std::integral_constant< : std::integral_constant<
bool, type_traits_internal::is_trivially_copyable_impl<T>::kValue> {}; bool, type_traits_internal::is_trivially_copyable_impl<T>::kValue> {};
#endif
} // namespace type_traits_internal } // namespace type_traits_internal
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -336,6 +336,7 @@ struct MovableNonCopyable { ...@@ -336,6 +336,7 @@ struct MovableNonCopyable {
struct NonCopyableOrMovable { struct NonCopyableOrMovable {
NonCopyableOrMovable() = default; NonCopyableOrMovable() = default;
virtual ~NonCopyableOrMovable() = default;
NonCopyableOrMovable(const NonCopyableOrMovable&) = delete; NonCopyableOrMovable(const NonCopyableOrMovable&) = delete;
NonCopyableOrMovable(NonCopyableOrMovable&&) = delete; NonCopyableOrMovable(NonCopyableOrMovable&&) = delete;
NonCopyableOrMovable& operator=(const NonCopyableOrMovable&) = delete; NonCopyableOrMovable& operator=(const NonCopyableOrMovable&) = delete;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment