From 74155db2438108b347f009c686fadcb7db82f8db Mon Sep 17 00:00:00 2001 From: Simon Brand Date: Fri, 11 May 2018 10:20:37 +0100 Subject: [PATCH] Fix #15 --- tl/expected.hpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tl/expected.hpp b/tl/expected.hpp index ee329c3..09370a5 100644 --- a/tl/expected.hpp +++ b/tl/expected.hpp @@ -184,6 +184,19 @@ static constexpr unexpect_t unexpect{}; /// \exclude namespace detail { +template +[[noreturn]] constexpr void throw_exception(E &&e) { +#if defined(__EXCEPTIONS) || defined(_CPPUNWIND) + throw std::forward(e); +#else + #ifdef _MSC_VER + __assume(0); + #else + __builtin_unreachable(); + #endif +#endif +} + #ifndef TL_TRAITS_MUTEX #define TL_TRAITS_MUTEX // C++14-style aliases for brevity @@ -1729,7 +1742,7 @@ public: detail::enable_if_t::value> * = nullptr> TL_EXPECTED_11_CONSTEXPR const U &value() const & { if (!has_value()) - throw bad_expected_access(err().value()); + detail::throw_exception(bad_expected_access(err().value())); return val(); } /// \group value @@ -1737,7 +1750,7 @@ public: detail::enable_if_t::value> * = nullptr> TL_EXPECTED_11_CONSTEXPR U &value() & { if (!has_value()) - throw bad_expected_access(err().value()); + detail::throw_exception(bad_expected_access(err().value())); return val(); } /// \group value @@ -1745,7 +1758,7 @@ public: detail::enable_if_t::value> * = nullptr> TL_EXPECTED_11_CONSTEXPR const U &&value() const && { if (!has_value()) - throw bad_expected_access(err().value()); + detail::throw_exception(bad_expected_access(err().value())); return std::move(val()); } /// \group value @@ -1753,7 +1766,7 @@ public: detail::enable_if_t::value> * = nullptr> TL_EXPECTED_11_CONSTEXPR U &&value() && { if (!has_value()) - throw bad_expected_access(err().value()); + detail::throw_exception(bad_expected_access(err().value())); return std::move(val()); }