From 76419a0d6f663b79d526864195e4a27a0f6ae3dc Mon Sep 17 00:00:00 2001 From: Nikolas Klauser 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 __value_type; typedef __unordered_map_hasher __hasher; typedef __unordered_map_equal __key_equal; - typedef __rebind_alloc, __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 __value_type; typedef __unordered_map_hasher __hasher; typedef __unordered_map_equal __key_equal; - typedef __rebind_alloc, __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 +#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, complete_type_allocator > > 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 +#include "min_allocator.h" #include "test_macros.h" template @@ -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, std::equal_to, complete_type_allocator > > + 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 +#include "min_allocator.h" #include "test_macros.h" template @@ -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, + std::equal_to, + complete_type_allocator > > + m; + return 0; }