Skip to content

Commit

Permalink
Add more debug capacity validation checks on merge/swap.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 673403995
Change-Id: I62d8bb37d4538c340783fb55e5a00694e932b6d1
  • Loading branch information
ezbr authored and copybara-github committed Sep 11, 2024
1 parent 67d1260 commit 0bc0e9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions absl/container/internal/raw_hash_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -3213,6 +3213,8 @@ class raw_hash_set {
// If the element already exists in `this`, it is left unmodified in `src`.
template <typename H, typename E>
void merge(raw_hash_set<Policy, H, E, Alloc>& src) { // NOLINT
AssertNotDebugCapacity();
src.AssertNotDebugCapacity();
assert(this != &src);
// Returns whether insertion took place.
const auto insert_slot = [this](slot_type* src_slot) {
Expand Down Expand Up @@ -3263,6 +3265,8 @@ class raw_hash_set {
IsNoThrowSwappable<hasher>() && IsNoThrowSwappable<key_equal>() &&
IsNoThrowSwappable<allocator_type>(
typename AllocTraits::propagate_on_container_swap{})) {
AssertNotDebugCapacity();
that.AssertNotDebugCapacity();
using std::swap;
swap_common(that);
swap(hash_ref(), that.hash_ref());
Expand Down
6 changes: 5 additions & 1 deletion absl/container/internal/raw_hash_set_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3685,11 +3685,15 @@ TEST(Table, MovedFromCallsFail) {
}

{
ABSL_ATTRIBUTE_UNUSED IntTable t1, t2;
ABSL_ATTRIBUTE_UNUSED IntTable t1, t2, t3;
t1.insert(1);
t2 = std::move(t1);
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(t1.contains(1), "moved-from");
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(t1.swap(t3), "moved-from");
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(t1.merge(t3), "moved-from");
}
{
ABSL_ATTRIBUTE_UNUSED IntTable t1;
Expand Down

0 comments on commit 0bc0e9a

Please sign in to comment.