Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libcxx/include/__hash_table
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first, const_it
__bucket_list_[__next_chash] = __before_first;
__chash = __next_chash;
}
} else { // When __next is a nullptr we've fully erased the last bucket. Update the bucket list accordingly.
__bucket_list_[__chash] = nullptr;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ int main(int, char**) {
assert(c.size() == 0);
assert(k == c.end());
}
{ // Make sure that we're properly updating the bucket list when we're erasing to the end
std::unordered_map<int, int> m;
m.insert(std::make_pair(1, 1));
m.insert(std::make_pair(2, 2));

{
auto pair = m.equal_range(1);
assert(pair.first != pair.second);
m.erase(pair.first, pair.second);
}

{
auto pair = m.equal_range(2);
assert(pair.first != pair.second);
m.erase(pair.first, pair.second);
}

m.insert(std::make_pair(3, 3));
assert(m.size() == 1);
assert(*m.begin() == std::make_pair(3, 3));
assert(++m.begin() == m.end());
}
#if TEST_STD_VER >= 11
{
typedef std::unordered_map<int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ int main(int, char**) {
for (const auto& v : map)
assert(v.first == 1 || v.first == collision_val);
}
{ // Make sure that we're properly updating the bucket list when we're erasing to the end
std::unordered_multimap<int, int> m;
m.insert(std::make_pair(1, 1));
m.insert(std::make_pair(2, 2));

{
auto pair = m.equal_range(1);
assert(pair.first != pair.second);
m.erase(pair.first, pair.second);
}

{
auto pair = m.equal_range(2);
assert(pair.first != pair.second);
m.erase(pair.first, pair.second);
}

m.insert(std::make_pair(3, 3));
assert(m.size() == 1);
assert(*m.begin() == std::make_pair(3, 3));
assert(++m.begin() == m.end());
}
#if TEST_STD_VER >= 11
{
typedef std::unordered_multimap<int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ int main(int, char**) {
for (const auto& v : map)
assert(v == 1 || v == collision_val);
}
{ // Make sure that we're properly updating the bucket list when we're erasing to the end
std::unordered_multiset<int> m;
m.insert(1);
m.insert(2);

{
auto pair = m.equal_range(1);
assert(pair.first != pair.second);
m.erase(pair.first, pair.second);
}

{
auto pair = m.equal_range(2);
assert(pair.first != pair.second);
m.erase(pair.first, pair.second);
}

m.insert(3);
assert(m.size() == 1);
assert(*m.begin() == 3);
assert(++m.begin() == m.end());
}
#if TEST_STD_VER >= 11
{
typedef std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C;
Expand Down
22 changes: 22 additions & 0 deletions libcxx/test/std/containers/unord/unord.set/erase_range.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ int main(int, char**) {
assert(c.size() == 0);
assert(k == c.end());
}
{ // Make sure that we're properly updating the bucket list when we're erasing to the end
std::unordered_set<int> m;
m.insert(1);
m.insert(2);

{
auto pair = m.equal_range(1);
assert(pair.first != pair.second);
m.erase(pair.first, pair.second);
}

{
auto pair = m.equal_range(2);
assert(pair.first != pair.second);
m.erase(pair.first, pair.second);
}

m.insert(3);
assert(m.size() == 1);
assert(*m.begin() == 3);
assert(++m.begin() == m.end());
}
#if TEST_STD_VER >= 11
{
typedef std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C;
Expand Down
Loading