diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index c3718328361..f5463fb553e 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h @@ -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() || diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 3d5f59a5b1f..f69fca3f29b 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -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. }