[llvm-branch-commits] [libcxx] [libc++] Fix type confusion in hash_{, multi}map (PR #183223)
Peter Collingbourne via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Feb 25 14:51:06 PST 2026
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/183223
>From 20718e13a5f9629918b04ffc0ac234fb1e6bec05 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <pcc at google.com>
Date: Tue, 24 Feb 2026 17:30:13 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.6-beta.1
---
libcxx/include/ext/hash_map | 18 +++++++-----------
.../gnu/hash_map/non_standard_layout.pass.cpp | 17 +++++++++++++++++
.../hash_multimap/non_standard_layout.pass.cpp | 17 +++++++++++++++++
3 files changed, 41 insertions(+), 11 deletions(-)
create mode 100644 libcxx/test/extensions/gnu/hash_map/non_standard_layout.pass.cpp
create mode 100644 libcxx/test/extensions/gnu/hash_multimap/non_standard_layout.pass.cpp
diff --git a/libcxx/include/ext/hash_map b/libcxx/include/ext/hash_map
index 09c981131ff96..7df44370df96b 100644
--- a/libcxx/include/ext/hash_map
+++ b/libcxx/include/ext/hash_map
@@ -426,12 +426,10 @@ public:
typedef const value_type& const_reference;
private:
- 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 __hash_map_hasher<value_type, hasher> __hasher;
+ typedef __hash_map_equal<value_type, key_equal> __key_equal;
- 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_;
@@ -577,7 +575,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, std::addressof(__h->__get_value().first), __k);
+ __node_traits::construct(__na, const_cast<_Key*>(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;
@@ -647,12 +645,10 @@ public:
typedef const value_type& const_reference;
private:
- 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 __hash_map_hasher<value_type, hasher> __hasher;
+ typedef __hash_map_equal<value_type, key_equal> __key_equal;
- 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_;
diff --git a/libcxx/test/extensions/gnu/hash_map/non_standard_layout.pass.cpp b/libcxx/test/extensions/gnu/hash_map/non_standard_layout.pass.cpp
new file mode 100644
index 0000000000000..8ade04d1292a8
--- /dev/null
+++ b/libcxx/test/extensions/gnu/hash_map/non_standard_layout.pass.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// 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;
+}
diff --git a/libcxx/test/extensions/gnu/hash_multimap/non_standard_layout.pass.cpp b/libcxx/test/extensions/gnu/hash_multimap/non_standard_layout.pass.cpp
new file mode 100644
index 0000000000000..f206e2bfad0af
--- /dev/null
+++ b/libcxx/test/extensions/gnu/hash_multimap/non_standard_layout.pass.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// 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;
+}
More information about the llvm-branch-commits
mailing list