Add moved-from validation for the case of self-move-assignment. PiperOrigin-RevId: 669363872 Change-Id: I2aeac23eb082a7bdabe65b3f55fd8adea6930386
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index c371832..f5463fb 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h
@@ -3777,7 +3777,7 @@ // 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() ||
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 3d5f59a..f69fca3 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc
@@ -2091,6 +2091,10 @@ 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. }