1From 70614679dae1cc4a157248c7c3302c7059dd327d Mon Sep 17 00:00:00 2001 2From: Abseil Team <absl-team@google.com> 3Date: Fri, 5 Aug 2022 06:56:05 -0700 4Subject: [PATCH 17/17] abseil-cpp: Map the absl::is_trivially_* functions to 5 their std impl 6 7There'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. 8 9PiperOrigin-RevId: 465554125 10Change-Id: I8674c3a5270ce3c654cdf58ae7dbd9d2bda8faa5 11(cherry picked from commit cfe27e79cfcbefb2b4479e04f80cbb299bc46965) 12 13Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 14--- 15 third_party/abseil-cpp/absl/base/config.h | 11 ++++++++++ 16 .../abseil-cpp/absl/meta/type_traits.h | 22 +++++++++++++++++++ 17 .../abseil-cpp/absl/meta/type_traits_test.cc | 1 + 18 3 files changed, 34 insertions(+) 19 20diff --git a/third_party/abseil-cpp/absl/base/config.h b/third_party/abseil-cpp/absl/base/config.h 21index 94f7fcb5d..2faed85a8 100644 22--- a/third_party/abseil-cpp/absl/base/config.h 23+++ b/third_party/abseil-cpp/absl/base/config.h 24@@ -273,6 +273,17 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || 25 #define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1 26 #endif 27 28+// ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE 29+// 30+// Checks whether `std::is_trivially_copyable<T>` is supported. 31+// 32+// Notes: Clang 15+ with libc++ supports these features, GCC hasn't been tested. 33+#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE) 34+#error ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE cannot be directly set 35+#elif defined(__clang__) && (__clang_major__ >= 15) 36+#define ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE 1 37+#endif 38+ 39 // ABSL_HAVE_THREAD_LOCAL 40 // 41 // Checks whether C++11's `thread_local` storage duration specifier is 42diff --git a/third_party/abseil-cpp/absl/meta/type_traits.h b/third_party/abseil-cpp/absl/meta/type_traits.h 43index d886cb30a..46b769069 100644 44--- a/third_party/abseil-cpp/absl/meta/type_traits.h 45+++ b/third_party/abseil-cpp/absl/meta/type_traits.h 46@@ -298,8 +298,12 @@ struct is_function 47 // https://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html#Type-Traits. 48 template <typename T> 49 struct is_trivially_destructible 50+#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 51+ : std::is_trivially_destructible<T> { 52+#else 53 : std::integral_constant<bool, __has_trivial_destructor(T) && 54 std::is_destructible<T>::value> { 55+#endif 56 #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 57 private: 58 static constexpr bool compliant = std::is_trivially_destructible<T>::value == 59@@ -347,9 +351,13 @@ struct is_trivially_destructible 60 // Nontrivially destructible types will cause the expression to be nontrivial. 61 template <typename T> 62 struct is_trivially_default_constructible 63+#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) 64+ : std::is_trivially_default_constructible<T> { 65+#else 66 : std::integral_constant<bool, __has_trivial_constructor(T) && 67 std::is_default_constructible<T>::value && 68 is_trivially_destructible<T>::value> { 69+#endif 70 #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \ 71 !defined( \ 72 ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION) 73@@ -381,10 +389,14 @@ struct is_trivially_default_constructible 74 // expression to be nontrivial. 75 template <typename T> 76 struct is_trivially_move_constructible 77+#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) 78+ : std::is_trivially_move_constructible<T> { 79+#else 80 : std::conditional< 81 std::is_object<T>::value && !std::is_array<T>::value, 82 type_traits_internal::IsTriviallyMoveConstructibleObject<T>, 83 std::is_reference<T>>::type::type { 84+#endif 85 #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \ 86 !defined( \ 87 ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION) 88@@ -490,9 +502,13 @@ struct is_trivially_move_assignable 89 // `is_trivially_assignable<T&, const T&>`. 90 template <typename T> 91 struct is_trivially_copy_assignable 92+#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 93+ : std::is_trivially_copy_assignable<T> { 94+#else 95 : std::integral_constant< 96 bool, __has_trivial_assign(typename std::remove_reference<T>::type) && 97 absl::is_copy_assignable<T>::value> { 98+#endif 99 #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 100 private: 101 static constexpr bool compliant = 102@@ -544,6 +560,11 @@ namespace type_traits_internal { 103 // destructible. Arrays of trivially copyable types are trivially copyable. 104 // 105 // We expose this metafunction only for internal use within absl. 106+ 107+#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE) 108+template <typename T> 109+struct is_trivially_copyable : std::is_trivially_copyable<T> {}; 110+#else 111 template <typename T> 112 class is_trivially_copyable_impl { 113 using ExtentsRemoved = typename std::remove_all_extents<T>::type; 114@@ -569,6 +590,7 @@ template <typename T> 115 struct is_trivially_copyable 116 : std::integral_constant< 117 bool, type_traits_internal::is_trivially_copyable_impl<T>::kValue> {}; 118+#endif 119 } // namespace type_traits_internal 120 121 // ----------------------------------------------------------------------------- 122diff --git a/third_party/abseil-cpp/absl/meta/type_traits_test.cc b/third_party/abseil-cpp/absl/meta/type_traits_test.cc 123index 0ef5b6655..fe96554de 100644 124--- a/third_party/abseil-cpp/absl/meta/type_traits_test.cc 125+++ b/third_party/abseil-cpp/absl/meta/type_traits_test.cc 126@@ -336,6 +336,7 @@ struct MovableNonCopyable { 127 128 struct NonCopyableOrMovable { 129 NonCopyableOrMovable() = default; 130+ virtual ~NonCopyableOrMovable() = default; 131 NonCopyableOrMovable(const NonCopyableOrMovable&) = delete; 132 NonCopyableOrMovable(NonCopyableOrMovable&&) = delete; 133 NonCopyableOrMovable& operator=(const NonCopyableOrMovable&) = delete; 134-- 1352.20.1 136 137