Skip to content

Commit d3b339e

Browse files
authored
[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.
1 parent 267b136 commit d3b339e

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

libcxx/include/unordered_map

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,8 @@ private:
967967
typedef __hash_value_type<key_type, mapped_type> __value_type;
968968
typedef __unordered_map_hasher<key_type, value_type, hasher, key_equal> __hasher;
969969
typedef __unordered_map_equal<key_type, value_type, key_equal, hasher> __key_equal;
970-
typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
971970

972-
typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
971+
typedef __hash_table<__value_type, __hasher, __key_equal, allocator_type> __table;
973972

974973
__table __table_;
975974

@@ -1777,9 +1776,8 @@ private:
17771776
typedef __hash_value_type<key_type, mapped_type> __value_type;
17781777
typedef __unordered_map_hasher<key_type, value_type, hasher, key_equal> __hasher;
17791778
typedef __unordered_map_equal<key_type, value_type, key_equal, hasher> __key_equal;
1780-
typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
17811779

1782-
typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
1780+
typedef __hash_table<__value_type, __hasher, __key_equal, allocator_type> __table;
17831781

17841782
__table __table_;
17851783

libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <map>
1515

16+
#include "min_allocator.h"
1617
#include "test_macros.h"
1718

1819
struct A {
@@ -28,5 +29,8 @@ inline bool operator<(A const& L, A const& R) { return L.data < R.data; }
2829
int main(int, char**) {
2930
A a;
3031

32+
// Make sure that the allocator isn't rebound to and incomplete type
33+
std::multimap<int, int, std::less<int>, complete_type_allocator<std::pair<const int, int> > > m;
34+
3135
return 0;
3236
}

libcxx/test/std/containers/unord/unord.map/incomplete_type.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <unordered_map>
1616

17+
#include "min_allocator.h"
1718
#include "test_macros.h"
1819

1920
template <class Tp>
@@ -36,5 +37,9 @@ inline bool operator==(A const& L, A const& R) { return &L == &R; }
3637
int main(int, char**) {
3738
A a;
3839

40+
// Make sure that the allocator isn't rebound to an incomplete type
41+
std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, complete_type_allocator<std::pair<const int, int> > >
42+
m;
43+
3944
return 0;
4045
}

libcxx/test/std/containers/unord/unord.multimap/incomplete.pass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <unordered_map>
1616

17+
#include "min_allocator.h"
1718
#include "test_macros.h"
1819

1920
template <class Tp>
@@ -36,5 +37,13 @@ inline bool operator==(A const& L, A const& R) { return &L == &R; }
3637
int main(int, char**) {
3738
A a;
3839

40+
// Make sure that the allocator isn't rebound to an incomplete type
41+
std::unordered_multimap<int,
42+
int,
43+
std::hash<int>,
44+
std::equal_to<int>,
45+
complete_type_allocator<std::pair<const int, int> > >
46+
m;
47+
3948
return 0;
4049
}

0 commit comments

Comments
 (0)