Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/tl/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ template <typename E>
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
throw std::forward<E>(e);
#else
(void)e;
#ifdef _MSC_VER
__assume(0);
#else
Expand Down Expand Up @@ -819,7 +820,7 @@ struct expected_operations_base : expected_storage_base<T, E> {
geterr().~unexpected<E>();
construct(std::move(rhs).get());
} else {
assign_common(rhs);
assign_common(std::move(rhs));
}
}

Expand Down
8 changes: 8 additions & 0 deletions tests/issues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::unique_ptr<int>, int> x1 {std::make_unique<int>(4)};
tl::expected<std::unique_ptr<int>, int> y1 {std::make_unique<int>(2)};
x1 = std::move(y1);

REQUIRE(**x1 == 2);
}
6 changes: 6 additions & 0 deletions tests/swap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<no_throw>::value, "");

template <class T1, class T2> void swap_test() {
Expand Down Expand Up @@ -79,6 +83,7 @@ template <class T1, class T2> void swap_test() {
REQUIRE(b.error().i == s1);
}

#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
TEST_CASE("swap") {

swap_test<no_throw, no_throw>();
Expand All @@ -99,3 +104,4 @@ TEST_CASE("swap") {
REQUIRE(a->i == s1);
REQUIRE(b.error().i == s2);
}
#endif // TL_EXPECTED_EXCEPTIONS_ENABLED