diff --git a/tests/issues.cpp b/tests/issues.cpp index 2dc4201..e89b829 100644 --- a/tests/issues.cpp +++ b/tests/issues.cpp @@ -5,22 +5,20 @@ using std::string; -tl::expected getInt3(int val) -{ - return val; -} +tl::expected getInt3(int val) { return val; } -tl::expected getInt2(int val) -{ - return val; -} +tl::expected getInt2(int val) { return val; } -tl::expected getInt1() -{ - return getInt2(5).and_then(getInt3); -} +tl::expected getInt1() { return getInt2(5).and_then(getInt3); } +TEST_CASE("Issue 1", "[issues.1]") { getInt1(); } -TEST_CASE("Issue 1", "[issues.1]") { - getInt1(); +tl::expected operation1() { return 42; } + +tl::expected operation2(int const val) { return "Bananas"; } + +TEST_CASE("Issue 17", "[issues.17]") { + auto const intermediate_result = operation1(); + + intermediate_result.and_then(operation2); } diff --git a/tl/expected.hpp b/tl/expected.hpp index a52f202..ee329c3 100644 --- a/tl/expected.hpp +++ b/tl/expected.hpp @@ -293,7 +293,7 @@ template ::value, bool = std::is_trivially_destructible::value> struct expected_storage_base { constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {} - constexpr expected_storage_base(no_init_t) : m_has_val(false) {} + constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {} template ::value> * = @@ -329,6 +329,7 @@ struct expected_storage_base { } } union { + char m_no_init; T m_val; unexpected m_unexpect; }; @@ -339,7 +340,7 @@ struct expected_storage_base { // so the destructor of the `expected` can be trivial. template struct expected_storage_base { constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {} - constexpr expected_storage_base(no_init_t) : m_has_val(false) {} + constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {} template ::value> * = @@ -369,6 +370,7 @@ template struct expected_storage_base { ~expected_storage_base() = default; union { + char m_no_init; T m_val; unexpected m_unexpect; }; @@ -379,7 +381,7 @@ template struct expected_storage_base { template struct expected_storage_base { constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {} TL_EXPECTED_MSVC2015_CONSTEXPR expected_storage_base(no_init_t) - : m_has_val(false) {} + : m_no_init(), m_has_val(false) {} template ::value> * = @@ -414,6 +416,7 @@ template struct expected_storage_base { } union { + char m_no_init; T m_val; unexpected m_unexpect; }; @@ -423,7 +426,7 @@ template struct expected_storage_base { // E is trivial, T is not. template struct expected_storage_base { constexpr expected_storage_base() : m_val(T{}), m_has_val(true) {} - constexpr expected_storage_base(no_init_t) : m_has_val(false) {} + constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {} template ::value> * = @@ -457,6 +460,7 @@ template struct expected_storage_base { } } union { + char m_no_init; T m_val; unexpected m_unexpect; }; @@ -466,7 +470,7 @@ template struct expected_storage_base { // `T` is `void`, `E` is trivially-destructible template struct expected_storage_base { TL_EXPECTED_MSVC2015_CONSTEXPR expected_storage_base() : m_has_val(true) {} - constexpr expected_storage_base(no_init_t) : m_has_val(false) {} + constexpr expected_storage_base(no_init_t) : m_val(), m_has_val(false) {} constexpr expected_storage_base(in_place_t) : m_has_val(true) {} @@ -522,6 +526,7 @@ template struct expected_storage_base { struct dummy {}; union { + char m_no_init; dummy m_val; unexpected m_unexpect; };