diff --recursive --unified tl-expected-1.0.1-orig/include/tl/expected.hpp tl-expected-1.0.1/include/tl/expected.hpp --- tl-expected-1.0.1-orig/include/tl/expected.hpp 2022-08-30 20:10:13.269489852 +0100 +++ tl-expected-1.0.1/include/tl/expected.hpp 2022-08-30 20:17:35.744258828 +0100 @@ -24,6 +24,7 @@ #include #include #include +#include #if defined(__EXCEPTIONS) || defined(_CPPUNWIND) #define TL_EXPECTED_EXCEPTIONS_ENABLED @@ -1862,27 +1863,37 @@ } } - constexpr const T *operator->() const { return valptr(); } - TL_EXPECTED_11_CONSTEXPR T *operator->() { return valptr(); } + constexpr const T *operator->() const { + assert(has_value()); + return valptr(); + } + TL_EXPECTED_11_CONSTEXPR T *operator->() { + assert(has_value()); + return valptr(); + } template ::value> * = nullptr> constexpr const U &operator*() const & { + assert(has_value()); return val(); } template ::value> * = nullptr> TL_EXPECTED_11_CONSTEXPR U &operator*() & { + assert(has_value()); return val(); } template ::value> * = nullptr> constexpr const U &&operator*() const && { + assert(has_value()); return std::move(val()); } template ::value> * = nullptr> TL_EXPECTED_11_CONSTEXPR U &&operator*() && { + assert(has_value()); return std::move(val()); } @@ -1918,10 +1929,22 @@ return std::move(val()); } - constexpr const E &error() const & { return err().value(); } - TL_EXPECTED_11_CONSTEXPR E &error() & { return err().value(); } - constexpr const E &&error() const && { return std::move(err().value()); } - TL_EXPECTED_11_CONSTEXPR E &&error() && { return std::move(err().value()); } + constexpr const E &error() const & { + assert(!has_value()); + return err().value(); + } + TL_EXPECTED_11_CONSTEXPR E &error() & { + assert(!has_value()); + return err().value(); + } + constexpr const E &&error() const && { + assert(!has_value()); + return std::move(err().value()); + } + TL_EXPECTED_11_CONSTEXPR E &&error() && { + assert(!has_value()); + return std::move(err().value()); + } template constexpr T value_or(U &&v) const & { static_assert(std::is_copy_constructible::value &&