Skip to content

Commit c837ff0

Browse files
committed
Don't copy unexpected object on throwing with exceptions disabled
1 parent 2089ecb commit c837ff0

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.14)
22
project(tl-expected
33
HOMEPAGE_URL https://tl.tartanllama.xyz
44
DESCRIPTION "C++11/14/17 std::expected with functional-style extensions"
5-
VERSION 1.2.0
5+
VERSION 1.3.0
66
LANGUAGES CXX)
77

88
include(CMakePackageConfigHelpers)

include/tl/expected.hpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define TL_EXPECTED_HPP
1818

1919
#define TL_EXPECTED_VERSION_MAJOR 1
20-
#define TL_EXPECTED_VERSION_MINOR 2
20+
#define TL_EXPECTED_VERSION_MINOR 3
2121
#define TL_EXPECTED_VERSION_PATCH 0
2222

2323
#include <exception>
@@ -219,20 +219,11 @@ struct unexpect_t {
219219
};
220220
static constexpr unexpect_t unexpect{};
221221

222-
namespace detail {
223-
template <typename E>
224-
[[noreturn]] TL_EXPECTED_11_CONSTEXPR void throw_exception(E &&e) {
225222
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
226-
throw std::forward<E>(e);
227-
#else
228-
(void)e;
229-
#ifdef _MSC_VER
230-
__assume(0);
231-
#else
232-
__builtin_unreachable();
223+
#define TL_EXPECTED_THROW_EXCEPTION(e) throw((e));
224+
#elif defined(_MSC_VER)
225+
#define TL_EXPECTED_THROW_EXCEPTION(e) std::terminate();
233226
#endif
234-
#endif
235-
}
236227

237228
#ifndef TL_TRAITS_MUTEX
238229
#define TL_TRAITS_MUTEX
@@ -2024,28 +2015,28 @@ class TL_EXPECTED_NODISCARD expected :
20242015
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
20252016
TL_EXPECTED_11_CONSTEXPR const U &value() const & {
20262017
if (!has_value())
2027-
detail::throw_exception(bad_expected_access<E>(err().value()));
2018+
TL_EXPECTED_THROW_EXCEPTION(bad_expected_access<E>(err().value()));
20282019
return val();
20292020
}
20302021
template <class U = T,
20312022
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
20322023
TL_EXPECTED_11_CONSTEXPR U &value() & {
20332024
if (!has_value())
2034-
detail::throw_exception(bad_expected_access<E>(err().value()));
2025+
TL_EXPECTED_THROW_EXCEPTION(bad_expected_access<E>(err().value()));
20352026
return val();
20362027
}
20372028
template <class U = T,
20382029
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
20392030
TL_EXPECTED_11_CONSTEXPR const U &&value() const && {
20402031
if (!has_value())
2041-
detail::throw_exception(bad_expected_access<E>(std::move(err()).value()));
2032+
TL_EXPECTED_THROW_EXCEPTION(bad_expected_access<E>(std::move(err()).value()));
20422033
return std::move(val());
20432034
}
20442035
template <class U = T,
20452036
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
20462037
TL_EXPECTED_11_CONSTEXPR U &&value() && {
20472038
if (!has_value())
2048-
detail::throw_exception(bad_expected_access<E>(std::move(err()).value()));
2039+
TL_EXPECTED_THROW_EXCEPTION(bad_expected_access<E>(std::move(err()).value()));
20492040
return std::move(val());
20502041
}
20512042

0 commit comments

Comments
 (0)