[libcxx-commits] [libcxx] [libc++] Don't instantiate allocators in __hash_table on an incomplete type (PR #148353)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jul 12 03:17:45 PDT 2025
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/148353
None
>From 76419a0d6f663b79d526864195e4a27a0f6ae3dc Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sat, 12 Jul 2025 12:17:23 +0200
Subject: [PATCH] [libc++] Don't instantiate allocators in __hash_table on an
incomplete type
---
libcxx/include/unordered_map | 6 ++----
.../associative/multimap/incomplete_type.pass.cpp | 4 ++++
.../containers/unord/unord.map/incomplete_type.pass.cpp | 5 +++++
.../containers/unord/unord.multimap/incomplete.pass.cpp | 9 +++++++++
4 files changed, 20 insertions(+), 4 deletions(-)
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