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

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 14 10:31:39 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
----------------
ldionne wrote:

In particular, this change is required or else we fail the test I added in `erase_iter.pass.cpp` which counts the number of assignments. Because of this, and since the semantics of what it means to be trivially relocatable are still being actively debated, I think it makes sense for us to err on the safer side and use `is_trivially_copyable` for now.

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


More information about the libcxx-commits mailing list