Skip to content

Commit 3449fbc

Browse files
committed
Fix #15
1 parent b53059c commit 3449fbc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

tests/issues.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@ TEST_CASE("issue 14") {
1717
REQUIRE(*v == 42);
1818
REQUIRE((&f->i) == (&*v));
1919
}
20+
21+
struct fail_on_copy_self {
22+
int value;
23+
fail_on_copy_self(int v) : value(v) {}
24+
fail_on_copy_self(const fail_on_copy_self& other) : value(other.value) {
25+
REQUIRE(&other != this);
26+
}
27+
};
28+
29+
TEST_CASE("issue 15") {
30+
tl::optional<fail_on_copy_self> o = fail_on_copy_self(42);
31+
32+
o = o;
33+
REQUIRE(o->value == 42);
34+
}

tl/optional.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ template <class T> struct optional_operations_base : optional_storage_base<T> {
424424
}
425425
}
426426

427-
if (rhs.has_value()) {
427+
else if (rhs.has_value()) {
428428
construct(std::forward<Opt>(rhs).get());
429429
}
430430
}

0 commit comments

Comments
 (0)