diff options
Diffstat (limited to 'absl/status')
-rw-r--r-- | absl/status/status.h | 8 | ||||
-rw-r--r-- | absl/status/status_test.cc | 6 |
2 files changed, 11 insertions, 3 deletions
diff --git a/absl/status/status.h b/absl/status/status.h index 9019e6c2..08d3e806 100644 --- a/absl/status/status.h +++ b/absl/status/status.h @@ -705,9 +705,11 @@ inline Status::Status(Status&& x) noexcept : rep_(x.rep_) { inline Status& Status::operator=(Status&& x) { uintptr_t old_rep = rep_; - rep_ = x.rep_; - x.rep_ = MovedFromRep(); - Unref(old_rep); + if (x.rep_ != old_rep) { + rep_ = x.rep_; + x.rep_ = MovedFromRep(); + Unref(old_rep); + } return *this; } diff --git a/absl/status/status_test.cc b/absl/status/status_test.cc index ca9488ad..25333fa2 100644 --- a/absl/status/status_test.cc +++ b/absl/status/status_test.cc @@ -397,6 +397,12 @@ TEST(Status, MoveAssignment) { assignee = std::move(status); EXPECT_EQ(assignee, copy); } + { + absl::Status status(absl::StatusCode::kInvalidArgument, "message"); + absl::Status copy(status); + status = static_cast<absl::Status&&>(status); + EXPECT_EQ(status, copy); + } } TEST(Status, Update) { |