diff --git a/src/program.cc b/src/program.cc index 5e72982a47..c9814b386b 100644 --- a/src/program.cc +++ b/src/program.cc @@ -83,6 +83,7 @@ Program::~Program() = default; Program& Program::operator=(Program&& program) { program.AssertNotMoved(); program.moved_ = true; + moved_ = false; id_ = std::move(program.id_); types_ = std::move(program.types_); ast_nodes_ = std::move(program.ast_nodes_); diff --git a/src/program_test.cc b/src/program_test.cc index c49c812cfa..3ec52c4b14 100644 --- a/src/program_test.cc +++ b/src/program_test.cc @@ -102,5 +102,16 @@ TEST_F(ProgramTest, DiagnosticsMove) { EXPECT_EQ(program_b.Diagnostics().begin()->message, "an error message"); } +TEST_F(ProgramTest, ReuseMovedFromVariable) { + Program a(std::move(*this)); + EXPECT_TRUE(a.IsValid()); + + Program b = std::move(a); + EXPECT_TRUE(b.IsValid()); + + a = std::move(b); + EXPECT_TRUE(a.IsValid()); +} + } // namespace } // namespace tint