summaryrefslogtreecommitdiff
path: root/absl/container/internal/raw_hash_set_test.cc
diff options
context:
space:
mode:
authorGravatar Evan Brown <ezb@google.com>2022-12-22 14:59:02 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2022-12-22 14:59:54 -0800
commitf7affaf32a6a396465507dd10520a3fe183d4e40 (patch)
tree6d62a7c86602c57cbfdf2dff2e31d3cb56c0f6dd /absl/container/internal/raw_hash_set_test.cc
parent8d77ac515bdd189b27d5006ee058c8898ceb756b (diff)
Fix a bug in iterator validation code in which we don't update the table's reserved growth if the reservation wouldn't grow the table.
PiperOrigin-RevId: 497246219 Change-Id: I9671236f56d10851c49de71c21899368be6c3a00
Diffstat (limited to 'absl/container/internal/raw_hash_set_test.cc')
-rw-r--r--absl/container/internal/raw_hash_set_test.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc
index 3bfb15f1..8096567c 100644
--- a/absl/container/internal/raw_hash_set_test.cc
+++ b/absl/container/internal/raw_hash_set_test.cc
@@ -2292,6 +2292,21 @@ TEST(Table, InvalidIteratorUseWithReserve) {
EXPECT_DEATH_IF_SUPPORTED(*it, kInvalidIteratorDeathMessage);
}
+TEST(Table, ReservedGrowthUpdatesWhenTableDoesntGrow) {
+ IntTable t;
+ for (int i = 0; i < 8; ++i) t.insert(i);
+ // Want to insert twice without invalidating iterators so reserve.
+ const size_t cap = t.capacity();
+ t.reserve(t.size() + 2);
+ // We want to be testing the case in which the reserve doesn't grow the table.
+ ASSERT_EQ(cap, t.capacity());
+ auto it = t.find(0);
+ t.insert(100);
+ t.insert(200);
+ // `it` shouldn't have been invalidated.
+ EXPECT_EQ(*it, 0);
+}
+
} // namespace
} // namespace container_internal
ABSL_NAMESPACE_END