Returning reference to *this from propagate_const
authorAaryaman Sagar <aary@instagram.com>
Fri, 22 Dec 2017 03:06:56 +0000 (19:06 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 22 Dec 2017 03:30:25 +0000 (19:30 -0800)
Summary: As title

Reviewed By: yfeldblum

Differential Revision: D6620395

fbshipit-source-id: 477aae84b2bbde2e79d46ae93c285909b56f575e

folly/lang/PropagateConst.h
folly/lang/test/PropagateConstTest.cpp

index 235db85aa139ebf46711dcebf240b93306e27d17..61c80d96726f95425033d197e868f7db1fa831fd 100644 (file)
@@ -124,6 +124,7 @@ class propagate_const {
           std::is_convertible<OtherPointer&&, Pointer>::value>>>
   FOLLY_CPP14_CONSTEXPR propagate_const& operator=(OtherPointer&& other) {
     pointer_ = static_cast<OtherPointer&&>(other);
+    return *this;
   }
 
   FOLLY_CPP14_CONSTEXPR void swap(propagate_const& other) noexcept(
index f68c28f1e5a19e8e5efdd3e969023c17ae5322f2..1a62f48d79c5bec191d72f7a890fd162a9867875 100644 (file)
@@ -68,6 +68,14 @@ TEST_F(PropagateConstTest, construct_assign) {
   EXPECT_FALSE((std::is_assignable<pc<Explicit>, pc<Source>>::value));
 }
 
+TEST_F(PropagateConstTest, op_assign_move) {
+  auto ptr = pc<std::unique_ptr<int>>{std::make_unique<int>(1)};
+  EXPECT_EQ(*ptr, 1);
+
+  ptr = std::make_unique<int>(2);
+  EXPECT_EQ(*ptr, 2);
+}
+
 TEST_F(PropagateConstTest, get) {
   int a = 3;
   auto pc_a = pc<int*>(&a);