Commit 9589f4c4 authored by Eric Niebler's avatar Eric Niebler Committed by Facebook Github Bot

rename ExpectedStorage::isThis to isSelfAssign so that the self-assign check in operator= works

Summary: This corrects an oversight in folly::Expected where self-assign was not being detected correctly due to a half-applied edit.

Reviewed By: yfeldblum

Differential Revision: D4348181

fbshipit-source-id: 710b25c4c6d7aeaaea50493ccc5788d875ec4c2e
parent a7ddbd6f
...@@ -445,7 +445,7 @@ struct ExpectedStorage<Value, Error, StorageType::eUnion> ...@@ -445,7 +445,7 @@ struct ExpectedStorage<Value, Error, StorageType::eUnion>
this->which_ = Which::eError; this->which_ = Which::eError;
} }
} }
bool isThis(const ExpectedStorage* that) const { bool isSelfAssign(const ExpectedStorage* that) const {
return this == that; return this == that;
} }
constexpr bool isSelfAssign(const void*) const { constexpr bool isSelfAssign(const void*) const {
......
...@@ -560,6 +560,36 @@ TEST(Expected, NoThrowMoveAssignable) { ...@@ -560,6 +560,36 @@ TEST(Expected, NoThrowMoveAssignable) {
(std::is_nothrow_move_assignable<Expected<ThrowingBadness, E>>::value)); (std::is_nothrow_move_assignable<Expected<ThrowingBadness, E>>::value));
} }
struct NoSelfAssign {
NoSelfAssign() = default;
NoSelfAssign(NoSelfAssign&&) = default;
NoSelfAssign(const NoSelfAssign&) = default;
NoSelfAssign& operator=(NoSelfAssign&& that) {
EXPECT_NE(this, &that);
return *this;
}
NoSelfAssign& operator=(const NoSelfAssign& that) {
EXPECT_NE(this, &that);
return *this;
}
};
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wself-move"
#endif
TEST(Expected, NoSelfAssign) {
folly::Expected<NoSelfAssign, int> e {NoSelfAssign{}};
e = e; // @nolint
e = std::move(e); // @nolint
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
struct NoDestructor {}; struct NoDestructor {};
struct WithDestructor { struct WithDestructor {
......
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