Skip to content

Commit

Permalink
Add more debug capacity validation checks on copies.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 675191249
Change-Id: I8fde03e0db6e014853730d63fa1924fd2290bf3e
  • Loading branch information
ezbr authored and copybara-github committed Sep 16, 2024
1 parent f7c22f5 commit ba835d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions absl/container/internal/raw_hash_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -2748,6 +2748,7 @@ class raw_hash_set {
raw_hash_set(const raw_hash_set& that, const allocator_type& a)
: raw_hash_set(GrowthToLowerboundCapacity(that.size()), that.hash_ref(),
that.eq_ref(), a) {
that.AssertNotDebugCapacity();
const size_t size = that.size();
if (size == 0) {
return;
Expand Down Expand Up @@ -2843,6 +2844,7 @@ class raw_hash_set {
}

raw_hash_set& operator=(const raw_hash_set& that) {
that.AssertNotDebugCapacity();
if (ABSL_PREDICT_FALSE(this == &that)) return *this;
constexpr bool propagate_alloc =
AllocTraits::propagate_on_container_copy_assignment::value;
Expand Down
2 changes: 2 additions & 0 deletions absl/container/internal/raw_hash_set_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3694,6 +3694,8 @@ TEST(Table, MovedFromCallsFail) {
EXPECT_DEATH_IF_SUPPORTED(t1.swap(t3), "moved-from");
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(t1.merge(t3), "moved-from");
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(IntTable{t1}, "moved-from");
}
{
ABSL_ATTRIBUTE_UNUSED IntTable t1;
Expand Down

0 comments on commit ba835d5

Please sign in to comment.