Skip to content

Commit de64c78

Browse files
committed
Fix missing death on linux
1 parent fcdb18f commit de64c78

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

‎Source/LuaBridge/detail/Expected.h‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,18 @@ class BadExpectedAccess : public std::runtime_error
10451045
};
10461046
#endif
10471047

1048+
namespace detail {
1049+
template <class E>
1050+
inline void throw_bad_expected_access_or_abort(E e)
1051+
{
1052+
#if LUABRIDGE_HAS_EXCEPTIONS
1053+
throw BadExpectedAccess<E>(std::move(e));
1054+
#else
1055+
std::abort();
1056+
#endif
1057+
}
1058+
} // namespace detail
1059+
10481060
template <class T>
10491061
struct is_expected : std::false_type
10501062
{
@@ -1296,40 +1308,33 @@ class Expected : public detail::expected_base<T, E, std::is_copy_constructible_v
12961308

12971309
constexpr const T& value() const& LUABRIDGE_IF_NO_EXCEPTIONS(noexcept)
12981310
{
1299-
#if LUABRIDGE_HAS_EXCEPTIONS
13001311
if (!hasValue())
1301-
throw BadExpectedAccess<E>(error());
1302-
#endif
1312+
detail::throw_bad_expected_access_or_abort(std::move(error()));
13031313

13041314
return base_type::value();
13051315
}
13061316

13071317
constexpr T& value() & LUABRIDGE_IF_NO_EXCEPTIONS(noexcept)
13081318
{
1309-
#if LUABRIDGE_HAS_EXCEPTIONS
13101319
if (!hasValue())
1311-
throw BadExpectedAccess<E>(error());
1312-
#endif
1320+
detail::throw_bad_expected_access_or_abort(std::move(error()));
13131321

13141322
return base_type::value();
13151323
}
13161324

13171325
constexpr const T&& value() const&& LUABRIDGE_IF_NO_EXCEPTIONS(noexcept)
13181326
{
1319-
#if LUABRIDGE_HAS_EXCEPTIONS
13201327
if (!hasValue())
1321-
throw BadExpectedAccess<E>(error());
1322-
#endif
1328+
detail::throw_bad_expected_access_or_abort(std::move(error()));
13231329

13241330
return std::move(base_type::value());
13251331
}
13261332

13271333
constexpr T&& value() && LUABRIDGE_IF_NO_EXCEPTIONS(noexcept)
13281334
{
1329-
#if LUABRIDGE_HAS_EXCEPTIONS
13301335
if (!hasValue())
1331-
throw BadExpectedAccess<E>(error());
1332-
#endif
1336+
detail::throw_bad_expected_access_or_abort(std::move(error()));
1337+
13331338
return std::move(base_type::value());
13341339
}
13351340

0 commit comments

Comments
 (0)