diff options
author | Aaron Jacobs <jacobsa@google.com> | 2023-03-27 16:08:18 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-03-27 16:08:57 -0700 |
commit | 6b4af2497bf3ec56b070fdd6d8c2cf5996c17dbe (patch) | |
tree | 010891fa4aa2f51f8b4263033e3c80d980d43d6a /absl/meta | |
parent | 0dc94309d367001176962db4ed3dc450a6448b31 (diff) |
type_traits: don't use __is_trivially_relocatable with Clang on Windows.
It currently gives the wrong result for types with a user-provided destructor:
struct S {
~S();
};
static_assert(!__is_trivially_relocatable(S));
PiperOrigin-RevId: 519855600
Change-Id: I5f0659ad0831974805a5ed4b615e3b6250d23154
Diffstat (limited to 'absl/meta')
-rw-r--r-- | absl/meta/type_traits.h | 11 | ||||
-rw-r--r-- | absl/meta/type_traits_test.cc | 22 |
2 files changed, 14 insertions, 19 deletions
diff --git a/absl/meta/type_traits.h b/absl/meta/type_traits.h index f713b78c..43bed500 100644 --- a/absl/meta/type_traits.h +++ b/absl/meta/type_traits.h @@ -495,11 +495,18 @@ using swap_internal::StdSwapIsUnconstrained; // Upstream documentation: // // https://clang.llvm.org/docs/LanguageExtensions.html#:~:text=__is_trivially_relocatable -// -#if ABSL_HAVE_BUILTIN(__is_trivially_relocatable) + // If the compiler offers a builtin that tells us the answer, we can use that. // This covers all of the cases in the fallback below, plus types that opt in // using e.g. [[clang::trivial_abi]]. +// +// Clang on Windows has the builtin, but it falsely claims types with a +// user-provided destructor are trivial (http://b/275003464). So we opt out +// there. +// +// TODO(b/275003464): remove the opt-out once the bug is fixed. +#if ABSL_HAVE_BUILTIN(__is_trivially_relocatable) && \ + !(defined(__clang__) && (defined(_WIN32) || defined(_WIN64))) template <class T> struct is_trivially_relocatable : std::integral_constant<bool, __is_trivially_relocatable(T)> {}; diff --git a/absl/meta/type_traits_test.cc b/absl/meta/type_traits_test.cc index d9e36887..7412f33d 100644 --- a/absl/meta/type_traits_test.cc +++ b/absl/meta/type_traits_test.cc @@ -780,20 +780,6 @@ TEST(TriviallyRelocatable, UserProvidedCopyConstructor) { static_assert(!absl::is_trivially_relocatable<S>::value, ""); } -// HACK: disable this test on Windows, which includes lexan, which gives the -// incorrect result for this case (http://b/275003464). -// -// TODO(b/275003464): make this hack more precise after figuring out how to -// detect --config=lexan in particular. If there is no reliable way, modify -// --config=lexan itself to set a define we can use. -// -// TODO(b/274984172): hoist this hack to the definition of -// absl::is_trivially_relocatable itself, since it's currently giving the wrong -// results under lexan. We can't trust __is_trivially_relocatable on that -// platform. -// -// TODO(b/275003464): remove this hack when the bug is fixed. -#if !(defined(_WIN32) || defined(_WIN64)) // A user-provided destructor disqualifies a type from being trivially // relocatable. TEST(TriviallyRelocatable, UserProvidedDestructor) { @@ -803,10 +789,12 @@ TEST(TriviallyRelocatable, UserProvidedDestructor) { static_assert(!absl::is_trivially_relocatable<S>::value, ""); } -#endif -#if defined(ABSL_HAVE_ATTRIBUTE_TRIVIAL_ABI) && \ - ABSL_HAVE_BUILTIN(__is_trivially_relocatable) +// TODO(b/275003464): remove the opt-out for Clang on Windows once +// __is_trivially_relocatable is used there again. +#if defined(ABSL_HAVE_ATTRIBUTE_TRIVIAL_ABI) && \ + ABSL_HAVE_BUILTIN(__is_trivially_relocatable) && \ + !(defined(__clang__) && (defined(_WIN32) || defined(_WIN64))) // A type marked with the "trivial ABI" attribute is trivially relocatable even // if it has user-provided move/copy constructors and a user-provided // destructor. |