diff --git a/tests/issues.cpp b/tests/issues.cpp index b271140..9aa84ad 100644 --- a/tests/issues.cpp +++ b/tests/issues.cpp @@ -105,4 +105,23 @@ TEST_CASE("Issue 42", "[issues.42]") { TEST_CASE("Issue 43", "[issues.43]") { auto result = tl::expected{}; result = tl::make_unexpected(std::string{ "foo" }); -} \ No newline at end of file +} + +#include + + using MaybeDataPtr = tl::expected>; + + MaybeDataPtr test(int i) noexcept + { + return std::move(i); + } + + MaybeDataPtr test2(int i) noexcept + { + return std::move(i); + } + +TEST_CASE("Issue 49", "[issues.49]") { + auto m = test(10) + .and_then(test2); +} diff --git a/tl/expected.hpp b/tl/expected.hpp index e16058d..2042c51 100644 --- a/tl/expected.hpp +++ b/tl/expected.hpp @@ -1910,7 +1910,7 @@ constexpr auto and_then_impl(Exp &&exp, F &&f) { return exp.has_value() ? detail::invoke(std::forward(f), *std::forward(exp)) - : Ret(unexpect, exp.error()); + : Ret(unexpect, std::forward(exp).error()); } template ::value, "F must return an expected"); return exp.has_value() ? detail::invoke(std::forward(f)) - : Ret(unexpect, exp.error()); + : Ret(unexpect, std::forward(exp).error()); } #else template struct TC; @@ -1933,7 +1933,7 @@ auto and_then_impl(Exp &&exp, F &&f) -> Ret { return exp.has_value() ? detail::invoke(std::forward(f), *std::forward(exp)) - : Ret(unexpect, exp.error()); + : Ret(unexpect, std::forward(exp).error()); } template Ret { static_assert(detail::is_expected::value, "F must return an expected"); return exp.has_value() ? detail::invoke(std::forward(f)) - : Ret(unexpect, exp.error()); + : Ret(unexpect, std::forward(exp).error()); } #endif