[libcxx-commits] [libcxx] [libc++] Take advantage of trivial relocation in std::vector::erase (PR #116268)

Richard Smith via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 14 13:04:54 PST 2024


================
@@ -23,14 +23,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 // A type is trivially relocatable if a move construct + destroy of the original object is equivalent to
 // `memcpy(dst, src, sizeof(T))`.
-
-#if __has_builtin(__is_trivially_relocatable)
-template <class _Tp, class = void>
-struct __libcpp_is_trivially_relocatable : integral_constant<bool, __is_trivially_relocatable(_Tp)> {};
-#else
+//
+// Note that we don't use Clang's __is_trivially_relocatable builtin because it doesn't honor the presence
+// of non-trivial special members like assignment operators, or even a copy constructor, making it possible
----------------
zygoloid wrote:

`TrackedAssignment` has a trivial destructor and a trivial copy constructor, so it's trivially relocatable by destroying it and copy-constructing a new instance. Is the library code not permitted to do that? If not, would it make sense to have separate internal traits for "trivially assignment-relocatable" versus "trivially construction-relocatable" that only detect the case where you could relocate specifically using assignment versus specifically using construction?

https://github.com/llvm/llvm-project/pull/116268


More information about the libcxx-commits mailing list