Commit a990998a authored by Alfred Fuller's avatar Alfred Fuller Committed by Facebook GitHub Bot

Fix forward_like rvalue->lvalue check

Summary: The static cast and forward were backwards. Previously it happily converted an rvalue to a const lvalue. Now it causes the exact same static_assert failure as std::forward in every rvalue->lvalue case.

Reviewed By: yfeldblum

Differential Revision: D26680263

fbshipit-source-id: f1ca4c4bfdd6333d24fe3c406d5373a2f72dea31
parent 38aaf9e0
...@@ -106,7 +106,7 @@ void as_const(T const&&) = delete; ...@@ -106,7 +106,7 @@ void as_const(T const&&) = delete;
// mimic: forward_like, p0847r0 // mimic: forward_like, p0847r0
template <typename Src, typename Dst> template <typename Src, typename Dst>
constexpr like_t<Src, Dst>&& forward_like(Dst&& dst) noexcept { constexpr like_t<Src, Dst>&& forward_like(Dst&& dst) noexcept {
return static_cast<like_t<Src, Dst>&&>(std::forward<Dst>(dst)); return std::forward<like_t<Src, Dst>>(static_cast<Dst&&>(dst));
} }
/** /**
......
...@@ -81,6 +81,11 @@ TEST_F(UtilityTest, forward_like) { ...@@ -81,6 +81,11 @@ TEST_F(UtilityTest, forward_like) {
// the real work is done by like_t, in terms of which forward_like is defined // the real work is done by like_t, in terms of which forward_like is defined
EXPECT_EQ(&x, std::addressof(folly::forward_like<char&>(x))); EXPECT_EQ(&x, std::addressof(folly::forward_like<char&>(x)));
EXPECT_EQ(&x, std::addressof(as_mutable(folly::forward_like<char const>(x)))); EXPECT_EQ(&x, std::addressof(as_mutable(folly::forward_like<char const>(x))));
// Should not be able to turn rvalues into lvalues
// Uncomment to produce expected compile-time errors
// std::forward<const int&>(1);
// folly::forward_like<const int&>(1);
} }
TEST_F(UtilityTest, MoveOnly) { TEST_F(UtilityTest, MoveOnly) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment