diff --git a/include/tl/expected.hpp b/include/tl/expected.hpp index f4f4b2c..f154190 100644 --- a/include/tl/expected.hpp +++ b/include/tl/expected.hpp @@ -208,6 +208,7 @@ template #ifdef TL_EXPECTED_EXCEPTIONS_ENABLED throw std::forward(e); #else + (void)e; #ifdef _MSC_VER __assume(0); #else @@ -824,7 +825,7 @@ struct expected_operations_base : expected_storage_base { geterr().~unexpected(); construct(std::move(rhs).get()); } else { - assign_common(rhs); + assign_common(std::move(rhs)); } } diff --git a/tests/issues.cpp b/tests/issues.cpp index 4b5c6fc..b8cde25 100644 --- a/tests/issues.cpp +++ b/tests/issues.cpp @@ -183,4 +183,12 @@ TEST_CASE("Issue 107", "[issues.107]") { REQUIRE(ex1.error().j == 0); REQUIRE(ex2.error().i == 2); REQUIRE(ex2.error().j == 2); +} + +TEST_CASE("Issue 129", "[issues.129]") { + tl::expected, int> x1 {std::make_unique(4)}; + tl::expected, int> y1 {std::make_unique(2)}; + x1 = std::move(y1); + + REQUIRE(**x1 == 2); } \ No newline at end of file diff --git a/tests/swap.cpp b/tests/swap.cpp index b3423c4..a5c92c3 100644 --- a/tests/swap.cpp +++ b/tests/swap.cpp @@ -14,6 +14,8 @@ struct canthrow_move { }; bool should_throw = false; + +#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED struct willthrow_move { willthrow_move(std::string i) : i(i) {} willthrow_move(willthrow_move const &) = default; @@ -24,6 +26,8 @@ struct willthrow_move { willthrow_move &operator=(willthrow_move &&) = default; std::string i; }; +#endif // TL_EXPECTED_EXCEPTIONS_ENABLED + static_assert(tl::detail::is_swappable::value, ""); template void swap_test() { @@ -79,6 +83,7 @@ template void swap_test() { REQUIRE(b.error().i == s1); } +#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED TEST_CASE("swap") { swap_test(); @@ -99,3 +104,4 @@ TEST_CASE("swap") { REQUIRE(a->i == s1); REQUIRE(b.error().i == s2); } +#endif // TL_EXPECTED_EXCEPTIONS_ENABLED