rename ExpectedStorage::isThis to isSelfAssign so that the self-assign check in opera...
authorEric Niebler <eniebler@fb.com>
Mon, 19 Dec 2016 23:12:31 +0000 (15:12 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 19 Dec 2016 23:18:23 +0000 (15:18 -0800)
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

folly/Expected.h
folly/test/ExpectedTest.cpp

index b4e63ee9dc5222d2c996128c4f9e7163429f87fe..5e6666db5d501f5f5df2e2673ec9d5f66b17c5a7 100644 (file)
@@ -445,7 +445,7 @@ struct ExpectedStorage<Value, Error, StorageType::eUnion>
       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 {
index a10c9e865ff12545ba4c79fcea9c6ab2fbf787c5..92acd0c1406b221a3c593ff564a77f2166d4f9c2 100644 (file)
@@ -560,6 +560,36 @@ TEST(Expected, NoThrowMoveAssignable) {
       (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 WithDestructor {