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
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
8 changes: 5 additions & 3 deletions stl/inc/format
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,8 @@ class basic_format_args;
_FMT_P2286_BEGIN
template <class _CharT>
struct _Format_handler;

struct _Monostate {};
_FMT_P2286_END

_EXPORT_STD template <class _Context>
Expand Down Expand Up @@ -818,7 +820,7 @@ private:

_Basic_format_arg_type _Active_state = _Basic_format_arg_type::_None;
union {
monostate _No_state = monostate{};
_Monostate _No_state{};
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
int _Int_state;
unsigned int _UInt_state;
long long _Long_long_state;
Expand Down Expand Up @@ -2417,7 +2419,7 @@ _EXPORT_STD using wformat_context = basic_format_context<_Fmt_wit, wchar_t>;

_FMT_P2286_BEGIN
template <class _CharT, class _OutputIt>
_NODISCARD _OutputIt _Fmt_write(_OutputIt _Out, monostate) {
_NODISCARD _OutputIt _Fmt_write(_OutputIt _Out, _Monostate) {
_STL_INTERNAL_CHECK(false);
return _Out;
}
Expand Down Expand Up @@ -2686,7 +2688,7 @@ _NODISCARD _OutputIt _Write_separated_integer(const char* _First, const char* co
}

template <class _CharT, class _OutputIt>
_NODISCARD _OutputIt _Fmt_write(_OutputIt _Out, monostate, const _Basic_format_specs<_CharT>&, _Lazy_locale) {
_NODISCARD _OutputIt _Fmt_write(_OutputIt _Out, _Monostate, const _Basic_format_specs<_CharT>&, _Lazy_locale) {
_STL_INTERNAL_CHECK(false);
return _Out;
}
Expand Down
2 changes: 2 additions & 0 deletions stl/inc/variant
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,8 @@ constexpr _Ret visit(_Callable&& _Obj, _Variants&&... _Args) {
}
#endif // _HAS_CXX20

_EXPORT_STD struct monostate {};

_EXPORT_STD _NODISCARD constexpr bool operator==(monostate, monostate) noexcept {
return true;
}
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
4 changes: 0 additions & 4 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -7170,10 +7170,6 @@ _NODISCARD constexpr bool _Is_finite(const _Ty _Xx) noexcept { // constexpr isfi
return _Float_abs_bits(_Xx) < _Traits::_Shifted_exponent_mask;
}

#if _HAS_CXX17
_EXPORT_STD struct monostate {};
#endif // _HAS_CXX17

#if _HAS_CXX23 && defined(__cpp_lib_concepts) // TRANSITION, GH-395
template <_Integer_like _Int>
_NODISCARD constexpr bool _Add_overflow(const _Int _Left, const _Int _Right, _Int& _Out) {
Expand Down