[libc++] Revert recent changes to __hash_table and ext/hash_map (#189427)

This reverts commits 30084d74765c and 5b8c17580482. The second commit
was landed without proper review: not by fault of the submitter, but
because I mistakenly thought this was modifying something else entirely
that is unsupported. The first commit must also be reverted because it
is a breaking change without the second commit.

This corresponds to PRs #183223 and #188660, see those for more details.
This commit is contained in:
Louis Dionne 2026-03-31 00:12:01 -04:00 committed by GitHub
parent 42cc454777
commit 8a0c070309
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 56 deletions

View File

@ -19,7 +19,6 @@
#include <__cstddef/ptrdiff_t.h>
#include <__cstddef/size_t.h>
#include <__functional/hash.h>
#include <__fwd/pair.h>
#include <__iterator/iterator_traits.h>
#include <__math/rounding_functions.h>
#include <__memory/addressof.h>
@ -1043,22 +1042,15 @@ private:
_LIBCPP_HIDE_FROM_ABI __next_pointer __detach() _NOEXCEPT;
template <class _From,
class _ValueT = _Tp,
__enable_if_t<__is_hash_value_type<_ValueT>::value || __is_pair_v<_ValueT>, int> = 0>
template <class _From, class _ValueT = _Tp, __enable_if_t<__is_hash_value_type<_ValueT>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI void __assign_value(__get_hash_node_value_type_t<_Tp>& __lhs, _From&& __rhs) {
// This is technically UB, since the object was constructed as `const`.
// Clang doesn't optimize on this currently though.
//
// The enable_if check for __is_pair_v is only needed to support
// __gnu_cxx::hash_map and may be removed if hash_map is removed.
const_cast<__remove_const_t<decltype(__lhs.first)>&>(__lhs.first) = std::forward<_From>(__rhs).first;
__lhs.second = std::forward<_From>(__rhs).second;
const_cast<key_type&>(__lhs.first) = const_cast<__copy_cvref_t<_From, key_type>&&>(__rhs.first);
__lhs.second = std::forward<_From>(__rhs).second;
}
template <class _From,
class _ValueT = _Tp,
__enable_if_t<!__is_hash_value_type<_ValueT>::value && !__is_pair_v<_ValueT>, int> = 0>
template <class _From, class _ValueT = _Tp, __enable_if_t<!__is_hash_value_type<_ValueT>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI void __assign_value(_Tp& __lhs, _From&& __rhs) {
__lhs = std::forward<_From>(__rhs);
}

View File

@ -426,10 +426,12 @@ public:
typedef const value_type& const_reference;
private:
typedef __hash_map_hasher<value_type, hasher> __hasher;
typedef __hash_map_equal<value_type, key_equal> __key_equal;
typedef std::pair<key_type, mapped_type> __value_type;
typedef __hash_map_hasher<__value_type, hasher> __hasher;
typedef __hash_map_equal<__value_type, key_equal> __key_equal;
typedef std::__rebind_alloc<std::allocator_traits<allocator_type>, __value_type> __allocator_type;
typedef std::__hash_table<value_type, __hasher, __key_equal, allocator_type> __table;
typedef std::__hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
__table __table_;
@ -575,7 +577,7 @@ typename hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k) {
__node_allocator& __na = __table_.__node_alloc();
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
__node_traits::construct(__na, const_cast<_Key*>(std::addressof(__h->__get_value().first)), __k);
__node_traits::construct(__na, std::addressof(__h->__get_value().first), __k);
__h.get_deleter().__first_constructed = true;
__node_traits::construct(__na, std::addressof(__h->__get_value().second));
__h.get_deleter().__second_constructed = true;
@ -645,10 +647,12 @@ public:
typedef const value_type& const_reference;
private:
typedef __hash_map_hasher<value_type, hasher> __hasher;
typedef __hash_map_equal<value_type, key_equal> __key_equal;
typedef std::pair<key_type, mapped_type> __value_type;
typedef __hash_map_hasher<__value_type, hasher> __hasher;
typedef __hash_map_equal<__value_type, key_equal> __key_equal;
typedef std::__rebind_alloc<std::allocator_traits<allocator_type>, __value_type> __allocator_type;
typedef std::__hash_table<value_type, __hasher, __key_equal, allocator_type> __table;
typedef std::__hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
__table __table_;

View File

@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated -Wno-deprecated-copy
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
// hash_map::hash_map(const hash_map&)
@ -23,9 +23,5 @@ int main(int, char**) {
assert(map2.size() == 2);
map.insert(std::make_pair(3, 1));
map2 = map;
assert(map2.size() == 3);
return 0;
}

View File

@ -1,16 +0,0 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
#include <ext/hash_map>
int main(int, char**) {
__gnu_cxx::hash_map<const char*, std::string> m;
auto it = m.insert(std::make_pair("foo", "bar")).first;
return it->first == nullptr;
}

View File

@ -1,16 +0,0 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated
#include <ext/hash_map>
int main(int, char**) {
__gnu_cxx::hash_multimap<const char*, std::string> m;
auto it = m.insert(std::make_pair("foo", "bar"));
return it->first == nullptr;
}