@@ -324,11 +324,17 @@ using swap_internal::Swap;
324324
325325// absl::is_trivially_relocatable<T>
326326//
327+ // https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2786r11.html
328+ //
327329// Detects whether a type is known to be "trivially relocatable" -- meaning it
328330// can be relocated from one place to another as if by memcpy/memmove.
329331// This implies that its object representation doesn't depend on its address,
330332// and also none of its special member functions do anything strange.
331333//
334+ // Note that when relocating the caller code should ensure that if the object is
335+ // polymorphic, the dynamic type is of the most derived type. Padding bytes
336+ // should not be copied.
337+ //
332338// This trait is conservative. If it's true then the type is definitely
333339// trivially relocatable, but if it's false then the type may or may not be. For
334340// example, std::vector<int> is trivially relocatable on every known STL
@@ -346,11 +352,7 @@ using swap_internal::Swap;
346352//
347353// Upstream documentation:
348354//
349- // https://clang.llvm.org/docs/LanguageExtensions.html#:~:text=__is_trivially_relocatable
350-
351- // If the compiler offers a builtin that tells us the answer, we can use that.
352- // This covers all of the cases in the fallback below, plus types that opt in
353- // using e.g. [[clang::trivial_abi]].
355+ // https://clang.llvm.org/docs/LanguageExtensions.html#:~:text=__builtin_is_cpp_trivially_relocatable
354356//
355357// Clang on Windows has the builtin, but it falsely claims types with a
356358// user-provided destructor are trivial (http://b/275003464). So we opt out
@@ -375,15 +377,22 @@ using swap_internal::Swap;
375377//
376378// According to https://github.com/abseil/abseil-cpp/issues/1479, this does not
377379// work with NVCC either.
378- #if ABSL_HAVE_BUILTIN(__is_trivially_relocatable) && \
379- (defined (__cpp_impl_trivially_relocatable) || \
380- (!defined (__clang__) && !defined (__APPLE__) && !defined (__NVCC__)))
380+ #if ABSL_HAVE_BUILTIN(__builtin_is_cpp_trivially_relocatable)
381+ // https://github.com/llvm/llvm-project/pull/127636#pullrequestreview-2637005293
382+ // In the current implementation, __builtin_is_cpp_trivially_relocatable will
383+ // only return true for types that are trivially relocatable according to the
384+ // standard. Notably, this means that marking a type [[clang::trivial_abi]] aka
385+ // ABSL_HAVE_ATTRIBUTE_TRIVIAL_ABI will have no effect on this trait.
381386template <class T >
382387struct is_trivially_relocatable
383- : std::integral_constant<bool , __is_trivially_relocatable(T)> {};
388+ : std::integral_constant<bool , __builtin_is_cpp_trivially_relocatable(T)> {
389+ };
384390#elif ABSL_HAVE_BUILTIN(__is_trivially_relocatable) && defined(__clang__) && \
385391 !(defined (_WIN32) || defined (_WIN64)) && !defined (__APPLE__) && \
386392 !defined (__NVCC__)
393+ // https://github.com/llvm/llvm-project/pull/139061
394+ // __is_trivially_relocatable is deprecated.
395+ // TODO(b/325479096): Remove this case.
387396template <class T >
388397struct is_trivially_relocatable
389398 : std::integral_constant<
0 commit comments