[all-commits] [llvm/llvm-project] 3a7d43: [libc++] Require the exact assignment expression t...
Yuxuan Chen via All-commits
all-commits at lists.llvm.org
Sat May 9 08:30:36 PDT 2026
Branch: refs/heads/users/yuxuanchen1997/libcxx-uninitialized-copy-assign
Home: https://github.com/llvm/llvm-project
Commit: 3a7d4301e8b481f940c6eba85e5908bc9ce650c3
https://github.com/llvm/llvm-project/commit/3a7d4301e8b481f940c6eba85e5908bc9ce650c3
Author: Yuxuan Chen <ych at meta.com>
Date: 2026-05-09 (Sat, 09 May 2026)
Changed paths:
M libcxx/include/__memory/uninitialized_algorithms.h
A libcxx/test/libcxx/memory/uninitialized_allocator_copy_template_op_assign.pass.cpp
Log Message:
-----------
[libc++] Require the exact assignment expression to be trivial in __uninitialized_allocator_copy_impl
__uninitialized_allocator_copy_impl has an optimization that replaces allocator_traits::construct with std::copy for raw pointer ranges when the element type is trivially copy constructible and trivially copy assignable.
The copy-assignment trait only checks whether assignment from const T& is trivial. That is weaker than the expression used by std::copy, which evaluates *out = *in. If overload resolution selects a different non-trivial assignment operator for that expression, std::copy can call that operator on uninitialized storage.
Check is_trivially_assignable<_Out&, _In&> instead. This matches the assignment expression used by std::copy, preserves the optimized path when that assignment is actually trivial, and falls back to placement construction otherwise.
Add a regression test with a type whose defaulted copy assignment is trivial but whose templated assignment operator is selected for non-const lvalue sources.
Tested with:
~/llvm-project/build-libcxx-fresh/bin/llvm-lit ~/llvm-project/libcxx/test/libcxx/memory/uninitialized_allocator_copy_template_op_assign.pass.cpp ~/llvm-project/libcxx/test/libcxx/memory/uninitialized_allocator_copy.pass.cpp -q
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list