From 6fe2af5191214cce620899f7f06585c047b9f1fc Mon Sep 17 00:00:00 2001 From: Simon Brand Date: Wed, 10 Jul 2019 09:26:02 +0100 Subject: [PATCH] Move the error value when throwing an exception in .value rval overloads (#62) * Move the error value when throwing an exception in .value rval overloads Fixes #61 * Bump version --- include/tl/expected.hpp | 6 +++--- tests/issues.cpp | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/tl/expected.hpp b/include/tl/expected.hpp index 97591d0..31a5193 100644 --- a/include/tl/expected.hpp +++ b/include/tl/expected.hpp @@ -18,7 +18,7 @@ #define TL_EXPECTED_VERSION_MAJOR 1 #define TL_EXPECTED_VERSION_MINOR 0 -#define TL_EXPECTED_VERSION_PATCH 0 +#define TL_EXPECTED_VERSION_PATCH 1 #include #include @@ -1907,14 +1907,14 @@ public: detail::enable_if_t::value> * = nullptr> TL_EXPECTED_11_CONSTEXPR const U &&value() const && { if (!has_value()) - detail::throw_exception(bad_expected_access(err().value())); + detail::throw_exception(bad_expected_access(std::move(err()).value())); return std::move(val()); } template ::value> * = nullptr> TL_EXPECTED_11_CONSTEXPR U &&value() && { if (!has_value()) - detail::throw_exception(bad_expected_access(err().value())); + detail::throw_exception(bad_expected_access(std::move(err()).value())); return std::move(val()); } diff --git a/tests/issues.cpp b/tests/issues.cpp index c2847ea..2cd16be 100644 --- a/tests/issues.cpp +++ b/tests/issues.cpp @@ -126,4 +126,13 @@ TEST_CASE("Issue 49", "[issues.49]") { auto m = test(10) .and_then(test2); } -#endif \ No newline at end of file +#endif + +tl::expected> func() +{ + return 1; +} + +TEST_CASE("Issue 61", "[issues.61]") { + REQUIRE(func().value() == 1); +} \ No newline at end of file