Skip to content

Commit e64dd62

Browse files
ezbrcopybara-github
authored andcommitted
Add moved-from validation for the case of self-move-assignment.
PiperOrigin-RevId: 669363872 Change-Id: I2aeac23eb082a7bdabe65b3f55fd8adea6930386
1 parent 1031858 commit e64dd62

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

absl/container/internal/raw_hash_set.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3777,7 +3777,7 @@ class raw_hash_set {
37773777
// We only enable moved-from validation when generations are enabled (rather
37783778
// than using NDEBUG) to avoid issues in which NDEBUG is enabled in some
37793779
// translation units but not in others.
3780-
if (SwisstableGenerationsEnabled() && this != &that) {
3780+
if (SwisstableGenerationsEnabled()) {
37813781
that.common().set_capacity(InvalidCapacity::kMovedFrom);
37823782
}
37833783
if (!SwisstableGenerationsEnabled() || capacity() == DefaultCapacity() ||

absl/container/internal/raw_hash_set_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,10 @@ TEST(Table, MoveSelfAssign) {
20912091
t.emplace("a", "b");
20922092
EXPECT_EQ(1, t.size());
20932093
t = std::move(*&t);
2094+
if (SwisstableGenerationsEnabled()) {
2095+
// NOLINTNEXTLINE(bugprone-use-after-move)
2096+
EXPECT_DEATH_IF_SUPPORTED(t.contains("a"), "");
2097+
}
20942098
// As long as we don't crash, it's fine.
20952099
}
20962100

0 commit comments

Comments
 (0)