Skip to content

Commit

Permalink
Add moved-from validation for the case of self-move-assignment.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 669363872
Change-Id: I2aeac23eb082a7bdabe65b3f55fd8adea6930386
  • Loading branch information
ezbr authored and copybara-github committed Aug 30, 2024
1 parent 1031858 commit e64dd62
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion absl/container/internal/raw_hash_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -3777,7 +3777,7 @@ class raw_hash_set {
// We only enable moved-from validation when generations are enabled (rather
// than using NDEBUG) to avoid issues in which NDEBUG is enabled in some
// translation units but not in others.
if (SwisstableGenerationsEnabled() && this != &that) {
if (SwisstableGenerationsEnabled()) {
that.common().set_capacity(InvalidCapacity::kMovedFrom);
}
if (!SwisstableGenerationsEnabled() || capacity() == DefaultCapacity() ||
Expand Down
4 changes: 4 additions & 0 deletions absl/container/internal/raw_hash_set_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,10 @@ TEST(Table, MoveSelfAssign) {
t.emplace("a", "b");
EXPECT_EQ(1, t.size());
t = std::move(*&t);
if (SwisstableGenerationsEnabled()) {
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(t.contains("a"), "");
}
// As long as we don't crash, it's fine.
}

Expand Down

0 comments on commit e64dd62

Please sign in to comment.