From: Eric Niebler Date: Mon, 19 Dec 2016 23:12:31 +0000 (-0800) Subject: rename ExpectedStorage::isThis to isSelfAssign so that the self-assign check in opera... X-Git-Tag: v2017.03.06.00~181 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=9589f4c4bc06e4bc72f0e5a3501b18a871b0e9be;p=folly.git 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 --- diff --git a/folly/Expected.h b/folly/Expected.h index b4e63ee9..5e6666db 100644 --- a/folly/Expected.h +++ b/folly/Expected.h @@ -445,7 +445,7 @@ struct ExpectedStorage this->which_ = Which::eError; } } - bool isThis(const ExpectedStorage* that) const { + bool isSelfAssign(const ExpectedStorage* that) const { return this == that; } constexpr bool isSelfAssign(const void*) const { diff --git a/folly/test/ExpectedTest.cpp b/folly/test/ExpectedTest.cpp index a10c9e86..92acd0c1 100644 --- a/folly/test/ExpectedTest.cpp +++ b/folly/test/ExpectedTest.cpp @@ -560,6 +560,36 @@ TEST(Expected, NoThrowMoveAssignable) { (std::is_nothrow_move_assignable>::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 e {NoSelfAssign{}}; + e = e; // @nolint + e = std::move(e); // @nolint +} + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + struct NoDestructor {}; struct WithDestructor {