[libcxx-commits] [libcxx] [libc++] Remove UB from `std::map` by updating `std::__tree_node` construction (PR #153908)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Sep 3 23:52:43 PDT 2025
================
@@ -1874,16 +1879,13 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&&... __args) {
__node_allocator& __na = __node_alloc();
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
- // Begin the lifetime of the node itself. Note that this doesn't begin the lifetime of the value
- // held inside the node, since we need to use the allocator's construct() method for that.
+ // Begin the lifetime of the node itself and the value_type contained within.
//
// We don't use the allocator's construct() method to construct the node itself since the
// Cpp17FooInsertable named requirements don't require the allocator's construct() method
// to work on anything other than the value_type.
- std::__construct_at(std::addressof(*__h), /* next = */ nullptr, /* hash = */ 0);
+ std::__construct_at(std::addressof(*__h), /* next = */ nullptr, /* hash = */ 0, __na, std::forward<_Args>(__args)...);
----------------
philnik777 wrote:
Do we ever construct the node with anything but `nullptr` and `0`? If not, I'd just move that into the constructor.
https://github.com/llvm/llvm-project/pull/153908
More information about the libcxx-commits
mailing list