[libcxx-commits] [libcxx] d3b339e - [libc++] Don't instantiate allocators in __hash_table on an incomplete type (#148353)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jul 12 23:59:10 PDT 2025
Author: Nikolas Klauser
Date: 2025-07-13T08:59:07+02:00
New Revision: d3b339e36debf208229e86bee3164bdf2ec24052
URL: https://github.com/llvm/llvm-project/commit/d3b339e36debf208229e86bee3164bdf2ec24052
DIFF: https://github.com/llvm/llvm-project/commit/d3b339e36debf208229e86bee3164bdf2ec24052.diff
LOG: [libc++] Don't instantiate allocators in __hash_table on an incomplete type (#148353)
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.
Added:
Modified:
libcxx/include/unordered_map
libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp
libcxx/test/std/containers/unord/unord.map/incomplete_type.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/incomplete.pass.cpp
Removed:
################################################################################
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;
}
More information about the libcxx-commits
mailing list