mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
Change the definition of is_trivially_relocatable to be a bit less conservative.
Instead of ignoring __is_trivially_relocatable, use __is_trivially_relocatable && std::is_trivially_move_assignable. PiperOrigin-RevId: 709106861 Change-Id: I2d53bd440133ad17bb676e53ee6a17d420a565d1
This commit is contained in:
committed by
Copybara-Service
parent
90a7ba66e8
commit
4198d9a96a
@@ -503,10 +503,11 @@ using swap_internal::Swap;
|
||||
// remove the condition.
|
||||
//
|
||||
// Clang on all platforms fails to detect that a type with a user-provided
|
||||
// move-assignment operator is not trivially relocatable. So in fact we
|
||||
// opt out of Clang altogether, for now.
|
||||
// move-assignment operator is not trivially relocatable so we also check for
|
||||
// is_trivially_move_assignable for Clang.
|
||||
//
|
||||
// TODO(b/325479096): Remove the opt-out once Clang's behavior is fixed.
|
||||
// TODO(b/325479096): Remove the Clang is_trivially_move_assignable version once
|
||||
// Clang's behavior is fixed.
|
||||
//
|
||||
// According to https://github.com/abseil/abseil-cpp/issues/1479, this does not
|
||||
// work with NVCC either.
|
||||
@@ -516,6 +517,15 @@ using swap_internal::Swap;
|
||||
template <class T>
|
||||
struct is_trivially_relocatable
|
||||
: std::integral_constant<bool, __is_trivially_relocatable(T)> {};
|
||||
#elif ABSL_HAVE_BUILTIN(__is_trivially_relocatable) && defined(__clang__) && \
|
||||
!(defined(_WIN32) || defined(_WIN64)) && !defined(__APPLE__) && \
|
||||
!defined(__NVCC__)
|
||||
template <class T>
|
||||
struct is_trivially_relocatable
|
||||
: std::integral_constant<
|
||||
bool, std::is_trivially_copyable<T>::value ||
|
||||
(__is_trivially_relocatable(T) &&
|
||||
std::is_trivially_move_assignable<T>::value)> {};
|
||||
#else
|
||||
// Otherwise we use a fallback that detects only those types we can feasibly
|
||||
// detect. Any type that is trivially copyable is by definition trivially
|
||||
|
||||
@@ -769,6 +769,8 @@ TEST(TriviallyRelocatable, UserProvidedDestructor) {
|
||||
// __is_trivially_relocatable is used there again.
|
||||
// TODO(b/324278148): remove the opt-out for Apple once
|
||||
// __is_trivially_relocatable is fixed there.
|
||||
// TODO(b/325479096): remove the opt-out for Clang once
|
||||
// __is_trivially_relocatable is fixed there.
|
||||
#if defined(ABSL_HAVE_ATTRIBUTE_TRIVIAL_ABI) && \
|
||||
ABSL_HAVE_BUILTIN(__is_trivially_relocatable) && \
|
||||
(defined(__cpp_impl_trivially_relocatable) || \
|
||||
@@ -779,8 +781,28 @@ TEST(TriviallyRelocatable, TrivialAbi) {
|
||||
struct ABSL_ATTRIBUTE_TRIVIAL_ABI S {
|
||||
S(S&&) {} // NOLINT(modernize-use-equals-default)
|
||||
S(const S&) {} // NOLINT(modernize-use-equals-default)
|
||||
void operator=(S&&) {}
|
||||
void operator=(const S&) {}
|
||||
S& operator=(S&&) { return *this; }
|
||||
S& operator=(const S&) { return *this; }
|
||||
~S() {} // NOLINT(modernize-use-equals-default)
|
||||
};
|
||||
|
||||
static_assert(absl::is_trivially_relocatable<S>::value, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO(b/275003464): remove the opt-out for Clang on Windows once
|
||||
// __is_trivially_relocatable is used there again.
|
||||
// TODO(b/324278148): remove the opt-out for Apple once
|
||||
// __is_trivially_relocatable is fixed there.
|
||||
#if defined(ABSL_HAVE_ATTRIBUTE_TRIVIAL_ABI) && \
|
||||
ABSL_HAVE_BUILTIN(__is_trivially_relocatable) && defined(__clang__) && \
|
||||
!(defined(_WIN32) || defined(_WIN64)) && !defined(__APPLE__) && \
|
||||
!defined(__NVCC__)
|
||||
// A type marked with the "trivial ABI" attribute is trivially relocatable even
|
||||
// if it has a user-provided copy constructor and a user-provided destructor.
|
||||
TEST(TriviallyRelocatable, TrivialAbi_NoUserProvidedMove) {
|
||||
struct ABSL_ATTRIBUTE_TRIVIAL_ABI S {
|
||||
S(const S&) {} // NOLINT(modernize-use-equals-default)
|
||||
~S() {} // NOLINT(modernize-use-equals-default)
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user