Skip to content

Conversation

@philnik777
Copy link
Contributor

@philnik777 philnik777 commented Jul 12, 2025

Currently, we try to instantiate the allocator on __hash_value_type, which we don't define anymore. Instead, just use the map::allocator_type to instantiate __tree, since that's what we actually want anyways.

@philnik777 philnik777 marked this pull request as ready for review July 13, 2025 06:59
@philnik777 philnik777 requested a review from a team as a code owner July 13, 2025 06:59
@philnik777 philnik777 merged commit d3b339e into llvm:main Jul 13, 2025
79 checks passed
@philnik777 philnik777 deleted the fix_hash_table_incomplete_type branch July 13, 2025 06:59
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jul 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 13, 2025

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

Currently, we try to instantiate the allocator on __hash_value_type, which we don't define anymore. Instead, just use the map::allocator_type to instantiate __tree, since that's what we actually want anyways.


Full diff: https://github.com/llvm/llvm-project/pull/148353.diff

4 Files Affected:

  • (modified) libcxx/include/unordered_map (+2-4)
  • (modified) libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp (+4)
  • (modified) libcxx/test/std/containers/unord/unord.map/incomplete_type.pass.cpp (+5)
  • (modified) libcxx/test/std/containers/unord/unord.multimap/incomplete.pass.cpp (+9)
diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map
index 30d7385673adf..5b70cdeae11a5 100644
--- a/libcxx/include/unordered_map
+++ b/libcxx/include/unordered_map
@@ -967,9 +967,8 @@ private:
   typedef __hash_value_type<key_type, mapped_type> __value_type;
   typedef __unordered_map_hasher<key_type, value_type, hasher, key_equal> __hasher;
   typedef __unordered_map_equal<key_type, value_type, key_equal, hasher> __key_equal;
-  typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
 
-  typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
+  typedef __hash_table<__value_type, __hasher, __key_equal, allocator_type> __table;
 
   __table __table_;
 
@@ -1777,9 +1776,8 @@ private:
   typedef __hash_value_type<key_type, mapped_type> __value_type;
   typedef __unordered_map_hasher<key_type, value_type, hasher, key_equal> __hasher;
   typedef __unordered_map_equal<key_type, value_type, key_equal, hasher> __key_equal;
-  typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
 
-  typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
+  typedef __hash_table<__value_type, __hasher, __key_equal, allocator_type> __table;
 
   __table __table_;
 
diff --git a/libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp b/libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp
index 05b8abf90e2ec..470275aea064b 100644
--- a/libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp
+++ b/libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp
@@ -13,6 +13,7 @@
 
 #include <map>
 
+#include "min_allocator.h"
 #include "test_macros.h"
 
 struct A {
@@ -28,5 +29,8 @@ inline bool operator<(A const& L, A const& R) { return L.data < R.data; }
 int main(int, char**) {
   A a;
 
+  // Make sure that the allocator isn't rebound to and incomplete type
+  std::multimap<int, int, std::less<int>, complete_type_allocator<std::pair<const int, int> > > m;
+
   return 0;
 }
diff --git a/libcxx/test/std/containers/unord/unord.map/incomplete_type.pass.cpp b/libcxx/test/std/containers/unord/unord.map/incomplete_type.pass.cpp
index 4b4d14d3b04f4..ba5e7e821b755 100644
--- a/libcxx/test/std/containers/unord/unord.map/incomplete_type.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.map/incomplete_type.pass.cpp
@@ -14,6 +14,7 @@
 
 #include <unordered_map>
 
+#include "min_allocator.h"
 #include "test_macros.h"
 
 template <class Tp>
@@ -36,5 +37,9 @@ inline bool operator==(A const& L, A const& R) { return &L == &R; }
 int main(int, char**) {
   A a;
 
+  // Make sure that the allocator isn't rebound to an incomplete type
+  std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, complete_type_allocator<std::pair<const int, int> > >
+      m;
+
   return 0;
 }
diff --git a/libcxx/test/std/containers/unord/unord.multimap/incomplete.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/incomplete.pass.cpp
index 2cc33030b552c..5a9855765daf9 100644
--- a/libcxx/test/std/containers/unord/unord.multimap/incomplete.pass.cpp
+++ b/libcxx/test/std/containers/unord/unord.multimap/incomplete.pass.cpp
@@ -14,6 +14,7 @@
 
 #include <unordered_map>
 
+#include "min_allocator.h"
 #include "test_macros.h"
 
 template <class Tp>
@@ -36,5 +37,13 @@ inline bool operator==(A const& L, A const& R) { return &L == &R; }
 int main(int, char**) {
   A a;
 
+  // Make sure that the allocator isn't rebound to an incomplete type
+  std::unordered_multimap<int,
+                          int,
+                          std::hash<int>,
+                          std::equal_to<int>,
+                          complete_type_allocator<std::pair<const int, int> > >
+      m;
+
   return 0;
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants