[libcxx-commits] [libcxx] [libc++] Remove UB from `std::map` by updating `std::__tree_node` construction (PR #153908)
Vinay Deshmukh via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Sep 6 07:24:32 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)...);
----------------
vinay-deshmukh wrote:
`nullptr` was used in all instances, but the `hash = ` arg can be 0 or a variable for the second occurrence, so that is still a constructor arg.
one more thing, for the second instance this was `0`, but then in the next line, it was being reassigned with a variable, so I changed that to be assigned through the constructor arg.
https://github.com/llvm/llvm-project/pull/153908
More information about the libcxx-commits
mailing list