From 9e3e54b932f7a35a42ef6ac584ca0a140f2acc1d Mon Sep 17 00:00:00 2001 From: Vasyl Teliman Date: Wed, 11 Aug 2021 13:50:24 +0000 Subject: [PATCH] Reuse moved-from tint::Program variables Currently, it's impossible to move a tint::Program instance into a variables that has been moved. This CL fixes that. Bug: tint:1105 Change-Id: Idc04cf2bb569d1cffc2c309117fc4615c41ac76a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/61640 Kokoro: Kokoro Reviewed-by: Ben Clayton Reviewed-by: Ryan Harrison Commit-Queue: Ryan Harrison --- src/program.cc | 1 + src/program_test.cc | 11 +++++++++++ 2 files changed, 12 insertions(+) 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