Commit e64dd622 by Evan Brown Committed by Copybara-Service

Add moved-from validation for the case of self-move-assignment.

PiperOrigin-RevId: 669363872
Change-Id: I2aeac23eb082a7bdabe65b3f55fd8adea6930386
parent 1031858e
...@@ -3777,7 +3777,7 @@ class raw_hash_set { ...@@ -3777,7 +3777,7 @@ class raw_hash_set {
// We only enable moved-from validation when generations are enabled (rather // We only enable moved-from validation when generations are enabled (rather
// than using NDEBUG) to avoid issues in which NDEBUG is enabled in some // than using NDEBUG) to avoid issues in which NDEBUG is enabled in some
// translation units but not in others. // translation units but not in others.
if (SwisstableGenerationsEnabled() && this != &that) { if (SwisstableGenerationsEnabled()) {
that.common().set_capacity(InvalidCapacity::kMovedFrom); that.common().set_capacity(InvalidCapacity::kMovedFrom);
} }
if (!SwisstableGenerationsEnabled() || capacity() == DefaultCapacity() || if (!SwisstableGenerationsEnabled() || capacity() == DefaultCapacity() ||
......
...@@ -2091,6 +2091,10 @@ TEST(Table, MoveSelfAssign) { ...@@ -2091,6 +2091,10 @@ TEST(Table, MoveSelfAssign) {
t.emplace("a", "b"); t.emplace("a", "b");
EXPECT_EQ(1, t.size()); EXPECT_EQ(1, t.size());
t = std::move(*&t); 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. // As long as we don't crash, it's fine.
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment