Skip to content

Commit

Permalink
Cleanups for <exception> (#3973)
Browse files Browse the repository at this point in the history
  • Loading branch information
achabense authored Sep 7, 2023
1 parent 9b468b3 commit d16d735
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
11 changes: 5 additions & 6 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -5293,14 +5293,14 @@ namespace chrono {
if constexpr (_Is_specialization_v<_Ty, duration>) {
if constexpr (!treat_as_floating_point_v<typename _Ty::rep>) {
if (_Specs._Precision != -1) {
_THROW(format_error("Precision specification invalid for chrono::duration type with "
"integral representation type, see N4950 [time.format]/1."));
_Throw_format_error("Precision specification invalid for chrono::duration type with "
"integral representation type, see N4950 [time.format]/1.");
}
}
} else {
if (_Specs._Precision != -1) {
_THROW(format_error("Precision specification invalid for non-chrono::duration type, "
"see N4950 [time.format]/1."));
_Throw_format_error("Precision specification invalid for non-chrono::duration type, "
"see N4950 [time.format]/1.");
}
}

Expand Down Expand Up @@ -5747,8 +5747,7 @@ namespace chrono {
return true;
} else if constexpr (is_same_v<_Ty, month_day_last>) {
if (_Val.month() >= February) {
_THROW(
format_error("The day of year for a month_day_last other than January is ambiguous"));
_Throw_format_error("The day of year for a month_day_last other than January is ambiguous");
}
return true;
} else if constexpr (_Is_ymd) {
Expand Down
23 changes: 8 additions & 15 deletions stl/inc/exception
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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()) {}
Expand All @@ -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()
};

Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d16d735

Please sign in to comment.