This commit is contained in:
Simon Brand
2018-06-08 12:35:38 +01:00
parent 72e23a137e
commit 414c1dafa1
2 changed files with 16 additions and 0 deletions

View File

@@ -22,3 +22,11 @@ TEST_CASE("Issue 17", "[issues.17]") {
intermediate_result.and_then(operation2); intermediate_result.and_then(operation2);
} }
struct a{};
struct b:a{};
TEST_CASE("Issue 26", "[issues.26]") {
tl::expected<a, int> exp = tl::expected<b,int>(tl::unexpect, 0);
REQUIRE(!exp.has_value());
}

View File

@@ -1487,8 +1487,10 @@ public:
: ctor_base(detail::default_constructor_tag{}) { : ctor_base(detail::default_constructor_tag{}) {
if (rhs.has_value()) { if (rhs.has_value()) {
::new (valptr()) T(*rhs); ::new (valptr()) T(*rhs);
this->m_has_val = true;
} else { } else {
::new (errptr()) unexpected_type(unexpected<E>(rhs.error())); ::new (errptr()) unexpected_type(unexpected<E>(rhs.error()));
this->m_has_val = false;
} }
} }
@@ -1503,8 +1505,10 @@ public:
: ctor_base(detail::default_constructor_tag{}) { : ctor_base(detail::default_constructor_tag{}) {
if (rhs.has_value()) { if (rhs.has_value()) {
::new (valptr()) T(*rhs); ::new (valptr()) T(*rhs);
this->m_has_val = true;
} else { } else {
::new (errptr()) unexpected_type(unexpected<E>(rhs.error())); ::new (errptr()) unexpected_type(unexpected<E>(rhs.error()));
this->m_has_val = false;
} }
} }
@@ -1517,8 +1521,10 @@ public:
: ctor_base(detail::default_constructor_tag{}) { : ctor_base(detail::default_constructor_tag{}) {
if (rhs.has_value()) { if (rhs.has_value()) {
::new (valptr()) T(std::move(*rhs)); ::new (valptr()) T(std::move(*rhs));
this->m_has_val = true;
} else { } else {
::new (errptr()) unexpected_type(unexpected<E>(std::move(rhs.error()))); ::new (errptr()) unexpected_type(unexpected<E>(std::move(rhs.error())));
this->m_has_val = false;
} }
} }
@@ -1532,8 +1538,10 @@ public:
: ctor_base(detail::default_constructor_tag{}) { : ctor_base(detail::default_constructor_tag{}) {
if (rhs.has_value()) { if (rhs.has_value()) {
::new (valptr()) T(std::move(*rhs)); ::new (valptr()) T(std::move(*rhs));
this->m_has_val = true;
} else { } else {
::new (errptr()) unexpected_type(unexpected<E>(std::move(rhs.error()))); ::new (errptr()) unexpected_type(unexpected<E>(std::move(rhs.error())));
this->m_has_val = false;
} }
} }