Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups for <exception> #3973

Merged
Merged
23 changes: 8 additions & 15 deletions stl/inc/exception
Original file line number Diff line number Diff line change
@@ -253,12 +253,6 @@ public:
return __ExceptionPtrToBool(this);
}

static exception_ptr _Current_exception() noexcept {
exception_ptr _Retval;
__ExceptionPtrCurrentException(&_Retval);
return _Retval;
}

static exception_ptr _Copy_exception(_In_ void* _Except, _In_ const void* _Ptr) {
exception_ptr _Retval;
if (!_Ptr) {
@@ -312,7 +306,9 @@ private:
};

_EXPORT_STD _NODISCARD inline exception_ptr current_exception() noexcept {
return exception_ptr::_Current_exception();
exception_ptr _Retval;
__ExceptionPtrCurrentException(&_Retval);
return _Retval;
}

_EXPORT_STD [[noreturn]] inline void rethrow_exception(_In_ exception_ptr _Ptr) {
@@ -327,10 +323,6 @@ _NODISCARD_SMART_PTR_ALLOC exception_ptr make_exception_ptr(_Ex _Except) noexcep
return exception_ptr::_Copy_exception(_STD addressof(_Except), __GetExceptionInfo(_Except));
}

[[noreturn]] inline void _Throw_bad_array_new_length() {
_THROW(bad_array_new_length{});
}

_EXPORT_STD class nested_exception { // wrap an exception_ptr
public:
nested_exception() noexcept : _Exc(_STD current_exception()) {}
@@ -355,9 +347,10 @@ private:
exception_ptr _Exc;
};

template <class _Ty, class _Uty>
struct _With_nested : _Uty, nested_exception { // glue user exception to nested_exception
explicit _With_nested(_Ty&& _Arg)
template <class _Uty>
struct _With_nested_v2 : _Uty, nested_exception { // glue user exception to nested_exception
template <class _Ty>
explicit _With_nested_v2(_Ty&& _Arg)
: _Uty(_STD forward<_Ty>(_Arg)), nested_exception() {} // store user exception and current_exception()
};

@@ -368,7 +361,7 @@ _EXPORT_STD template <class _Ty>

if constexpr (is_class_v<_Uty> && !is_base_of_v<nested_exception, _Uty> && !is_final_v<_Uty>) {
// throw user exception glued to nested_exception
using _Glued = _With_nested<_Ty, _Uty>;
using _Glued = _With_nested_v2<_Uty>;
_THROW(_Glued(_STD forward<_Ty>(_Arg)));
} else {
// throw user exception by itself
4 changes: 4 additions & 0 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
@@ -60,6 +60,10 @@ template <class _Keycmp, class _Lhs, class _Rhs>
_INLINE_VAR constexpr bool _Nothrow_compare = noexcept(
static_cast<bool>(_STD declval<const _Keycmp&>()(_STD declval<const _Lhs&>(), _STD declval<const _Rhs&>())));

[[noreturn]] inline void _Throw_bad_array_new_length() {
_THROW(bad_array_new_length{});
}

template <size_t _Ty_size>
_NODISCARD constexpr size_t _Get_size_of_n(const size_t _Count) {
constexpr bool _Overflow_is_possible = _Ty_size > 1;