From 3449fbc904dcfa5738905befd8114bdfda82f1ec Mon Sep 17 00:00:00 2001 From: Simon Brand Date: Fri, 12 Oct 2018 13:34:03 +0100 Subject: [PATCH] Fix #15 --- tests/issues.cpp | 15 +++++++++++++++ tl/optional.hpp | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/issues.cpp b/tests/issues.cpp index 50211fe..387b083 100644 --- a/tests/issues.cpp +++ b/tests/issues.cpp @@ -17,3 +17,18 @@ TEST_CASE("issue 14") { REQUIRE(*v == 42); REQUIRE((&f->i) == (&*v)); } + +struct fail_on_copy_self { + int value; + fail_on_copy_self(int v) : value(v) {} + fail_on_copy_self(const fail_on_copy_self& other) : value(other.value) { + REQUIRE(&other != this); + } +}; + +TEST_CASE("issue 15") { + tl::optional o = fail_on_copy_self(42); + + o = o; + REQUIRE(o->value == 42); +} \ No newline at end of file diff --git a/tl/optional.hpp b/tl/optional.hpp index 356254e..c63d820 100644 --- a/tl/optional.hpp +++ b/tl/optional.hpp @@ -424,7 +424,7 @@ template struct optional_operations_base : optional_storage_base { } } - if (rhs.has_value()) { + else if (rhs.has_value()) { construct(std::forward(rhs).get()); } }