diff --git a/tests/issues.cpp b/tests/issues.cpp index e89b829..241a0df 100644 --- a/tests/issues.cpp +++ b/tests/issues.cpp @@ -22,3 +22,11 @@ TEST_CASE("Issue 17", "[issues.17]") { intermediate_result.and_then(operation2); } + +struct a{}; +struct b:a{}; + +TEST_CASE("Issue 26", "[issues.26]") { + tl::expected exp = tl::expected(tl::unexpect, 0); + REQUIRE(!exp.has_value()); +} diff --git a/tl/expected.hpp b/tl/expected.hpp index a4be506..34da3d6 100644 --- a/tl/expected.hpp +++ b/tl/expected.hpp @@ -1487,8 +1487,10 @@ public: : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { ::new (valptr()) T(*rhs); + this->m_has_val = true; } else { ::new (errptr()) unexpected_type(unexpected(rhs.error())); + this->m_has_val = false; } } @@ -1503,8 +1505,10 @@ public: : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { ::new (valptr()) T(*rhs); + this->m_has_val = true; } else { ::new (errptr()) unexpected_type(unexpected(rhs.error())); + this->m_has_val = false; } } @@ -1517,8 +1521,10 @@ public: : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { ::new (valptr()) T(std::move(*rhs)); + this->m_has_val = true; } else { ::new (errptr()) unexpected_type(unexpected(std::move(rhs.error()))); + this->m_has_val = false; } } @@ -1532,8 +1538,10 @@ public: : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { ::new (valptr()) T(std::move(*rhs)); + this->m_has_val = true; } else { ::new (errptr()) unexpected_type(unexpected(std::move(rhs.error()))); + this->m_has_val = false; } }