Move the error value when throwing an exception in .value rval overloads

Fixes #55
This commit is contained in:
Simon Brand
2019-07-09 19:35:56 +01:00
parent 3d741708b9
commit 8f34e67f64
2 changed files with 12 additions and 3 deletions

View File

@ -1907,14 +1907,14 @@ public:
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR const U &&value() const && {
if (!has_value())
detail::throw_exception(bad_expected_access<E>(err().value()));
detail::throw_exception(bad_expected_access<E>(std::move(err()).value()));
return std::move(val());
}
template <class U = T,
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
TL_EXPECTED_11_CONSTEXPR U &&value() && {
if (!has_value())
detail::throw_exception(bad_expected_access<E>(err().value()));
detail::throw_exception(bad_expected_access<E>(std::move(err()).value()));
return std::move(val());
}

View File

@ -126,4 +126,13 @@ TEST_CASE("Issue 49", "[issues.49]") {
auto m = test(10)
.and_then(test2);
}
#endif
#endif
tl::expected<int, std::unique_ptr<std::string>> func()
{
return 1;
}
TEST_CASE("Issue 61", "[issues.61]") {
REQUIRE(func().value() == 1);
}