diff --git a/google/cloud/status_or.h b/google/cloud/status_or.h index c8c5e3562af47..7bf70d7293213 100644 --- a/google/cloud/status_or.h +++ b/google/cloud/status_or.h @@ -105,16 +105,11 @@ class StatusOr final { StatusOr(StatusOr const&) = default; StatusOr& operator=(StatusOr const&) = default; - // NOLINTNEXTLINE(performance-noexcept-move-constructor) - StatusOr(StatusOr&& other) - : status_(std::move(other.status_)), value_(std::move(other.value_)) { - other.status_ = MakeDefaultStatus(); - } - // NOLINTNEXTLINE(performance-noexcept-move-constructor) - StatusOr& operator=(StatusOr&& other) { + StatusOr(StatusOr&& other) noexcept + : status_(std::move(other.status_)), value_(std::move(other.value_)) {} + StatusOr& operator=(StatusOr&& other) noexcept { status_ = std::move(other.status_); value_ = std::move(other.value_); - other.status_ = MakeDefaultStatus(); return *this; } diff --git a/google/cloud/status_or_test.cc b/google/cloud/status_or_test.cc index 4c3c22803b0e4..b941515c4fbc0 100644 --- a/google/cloud/status_or_test.cc +++ b/google/cloud/status_or_test.cc @@ -184,11 +184,9 @@ TEST(StatusOrTest, MovedFromState) { EXPECT_STATUS_OK(a); EXPECT_EQ(123, *a); - // Asserts that a moved-from StatusOr is equal to a default constructed one. auto b = std::move(a); - EXPECT_EQ(a, StatusOr{}); // NOLINT(bugprone-use-after-move) a = std::move(b); - EXPECT_EQ(b, StatusOr{}); // NOLINT(bugprone-use-after-move) + EXPECT_THAT(a, IsOkAndHolds(123)); } TEST(StatusOrTest, AssignmentNotAmbiguous) { @@ -262,7 +260,6 @@ TEST(StatusOrObservableTest, MoveAssignmentNoValueNoValue) { Observable::reset_counters(); assigned = std::move(other); - EXPECT_FALSE(other.ok()); // NOLINT(bugprone-use-after-move) EXPECT_FALSE(assigned.ok()); EXPECT_EQ(0, Observable::destructor()); EXPECT_EQ(0, Observable::move_assignment()); @@ -316,7 +313,6 @@ TEST(StatusOrObservableTest, MoveAssignmentValueNoValue) { Observable::reset_counters(); assigned = std::move(other); - EXPECT_FALSE(other.ok()); // NOLINT(bugprone-use-after-move) EXPECT_FALSE(assigned.ok()); EXPECT_EQ(1, Observable::destructor()); EXPECT_EQ(0, Observable::move_assignment());