From: Aaryaman Sagar Date: Fri, 22 Dec 2017 03:06:56 +0000 (-0800) Subject: Returning reference to *this from propagate_const X-Git-Tag: v2017.12.25.00~5 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=22df45211b731dd86b1dbfaab9417b41376a51c8;p=folly.git Returning reference to *this from propagate_const Summary: As title Reviewed By: yfeldblum Differential Revision: D6620395 fbshipit-source-id: 477aae84b2bbde2e79d46ae93c285909b56f575e --- diff --git a/folly/lang/PropagateConst.h b/folly/lang/PropagateConst.h index 235db85a..61c80d96 100644 --- a/folly/lang/PropagateConst.h +++ b/folly/lang/PropagateConst.h @@ -124,6 +124,7 @@ class propagate_const { std::is_convertible::value>>> FOLLY_CPP14_CONSTEXPR propagate_const& operator=(OtherPointer&& other) { pointer_ = static_cast(other); + return *this; } FOLLY_CPP14_CONSTEXPR void swap(propagate_const& other) noexcept( diff --git a/folly/lang/test/PropagateConstTest.cpp b/folly/lang/test/PropagateConstTest.cpp index f68c28f1..1a62f48d 100644 --- a/folly/lang/test/PropagateConstTest.cpp +++ b/folly/lang/test/PropagateConstTest.cpp @@ -68,6 +68,14 @@ TEST_F(PropagateConstTest, construct_assign) { EXPECT_FALSE((std::is_assignable, pc>::value)); } +TEST_F(PropagateConstTest, op_assign_move) { + auto ptr = pc>{std::make_unique(1)}; + EXPECT_EQ(*ptr, 1); + + ptr = std::make_unique(2); + EXPECT_EQ(*ptr, 2); +} + TEST_F(PropagateConstTest, get) { int a = 3; auto pc_a = pc(&a);