[libcxx-commits] [libcxx] [libc++] Fix __gnu_cxx::hash_multimap copy construction (PR #160043)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 22 00:53:37 PDT 2025


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/160043

None

>From c43f74d4444fc6963b226b1c22c57570450bc868 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Mon, 22 Sep 2025 09:52:50 +0200
Subject: [PATCH] [libc++] Fix __gnu_cxx::hash_multimap copy construction

---
 libcxx/include/ext/hash_map                   |  5 +---
 .../gnu/hash_multimap/copy.pass.cpp           | 27 +++++++++++++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)
 create mode 100644 libcxx/test/extensions/gnu/hash_multimap/copy.pass.cpp

diff --git a/libcxx/include/ext/hash_map b/libcxx/include/ext/hash_map
index 70c2fbeec2959..01ca7498f0cc1 100644
--- a/libcxx/include/ext/hash_map
+++ b/libcxx/include/ext/hash_map
@@ -787,10 +787,7 @@ hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(
 }
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
-hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(const hash_multimap& __u) : __table_(__u.__table_) {
-  __table_.__rehash_multi(__u.bucket_count());
-  insert(__u.begin(), __u.end());
-}
+hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::hash_multimap(const hash_multimap& __u) : __table_(__u.__table_) {}
 
 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
 template <class _InputIterator>
diff --git a/libcxx/test/extensions/gnu/hash_multimap/copy.pass.cpp b/libcxx/test/extensions/gnu/hash_multimap/copy.pass.cpp
new file mode 100644
index 0000000000000..9f9737b28e44d
--- /dev/null
+++ b/libcxx/test/extensions/gnu/hash_multimap/copy.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// hash_multimap::hash_multimap(const hash_multimap&)
+
+#include <cassert>
+#include <ext/hash_map>
+
+int main(int, char**) {
+  __gnu_cxx::hash_multimap<int, int> map;
+
+  map.insert(std::make_pair(1, 1));
+  map.insert(std::make_pair(1, 1));
+
+  auto map2 = map;
+
+  assert(map2.size() == 2);
+
+  return 0;
+}



More information about the libcxx-commits mailing list