From 22df45211b731dd86b1dbfaab9417b41376a51c8 Mon Sep 17 00:00:00 2001 From: Aaryaman Sagar Date: Thu, 21 Dec 2017 19:06:56 -0800 Subject: [PATCH] Returning reference to *this from propagate_const Summary: As title Reviewed By: yfeldblum Differential Revision: D6620395 fbshipit-source-id: 477aae84b2bbde2e79d46ae93c285909b56f575e --- folly/lang/PropagateConst.h | 1 + folly/lang/test/PropagateConstTest.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) 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); -- 2.34.1