From b4aecea3f6d80daaa9fb63da9a2527973abbee7e Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:32:44 +0800 Subject: [PATCH 1/8] move `monostate` back to `` fix --- stl/inc/format | 8 +++++--- stl/inc/variant | 2 ++ stl/inc/xutility | 4 ---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/stl/inc/format b/stl/inc/format index 5b976f2f5d8..1a7584baf1d 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -688,6 +688,8 @@ class basic_format_args; _FMT_P2286_BEGIN template struct _Format_handler; + +struct _Monostate {}; _FMT_P2286_END _EXPORT_STD template @@ -818,7 +820,7 @@ private: _Basic_format_arg_type _Active_state = _Basic_format_arg_type::_None; union { - monostate _No_state = monostate{}; + _Monostate _No_state{}; int _Int_state; unsigned int _UInt_state; long long _Long_long_state; @@ -2417,7 +2419,7 @@ _EXPORT_STD using wformat_context = basic_format_context<_Fmt_wit, wchar_t>; _FMT_P2286_BEGIN template -_NODISCARD _OutputIt _Fmt_write(_OutputIt _Out, monostate) { +_NODISCARD _OutputIt _Fmt_write(_OutputIt _Out, _Monostate) { _STL_INTERNAL_CHECK(false); return _Out; } @@ -2686,7 +2688,7 @@ _NODISCARD _OutputIt _Write_separated_integer(const char* _First, const char* co } template -_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; } diff --git a/stl/inc/variant b/stl/inc/variant index b1da693c42d..6c78314cec3 100644 --- a/stl/inc/variant +++ b/stl/inc/variant @@ -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; } diff --git a/stl/inc/xutility b/stl/inc/xutility index 880293a0d71..e4cb6f93901 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -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) { From 12bfbb7565cdb35fbb5b7a63f30b9931ed755cb0 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:35:26 +0800 Subject: [PATCH 2/8] move `bad_variant_access` back to `` --- stl/inc/exception | 21 --------------------- stl/inc/variant | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/stl/inc/exception b/stl/inc/exception index 72bf3d74edf..b48d33e94a7 100644 --- a/stl/inc/exception +++ b/stl/inc/exception @@ -396,27 +396,6 @@ _EXPORT_STD template void rethrow_if_nested(const _Ty&) = delete; // requires /GR option #endif // ^^^ !defined(_CPPRTTI) ^^^ -_EXPORT_STD class bad_variant_access - : public exception { // exception for visit of a valueless variant or get on a variant with index() != I -public: - bad_variant_access() noexcept = default; - - _NODISCARD const char* __CLR_OR_THIS_CALL what() const noexcept override { - return "bad variant access"; - } - -#if !_HAS_EXCEPTIONS -protected: - void _Doraise() const override { // perform class-specific exception handling - _RAISE(*this); - } -#endif // ^^^ !_HAS_EXCEPTIONS ^^^ -}; - -[[noreturn]] inline void _Throw_bad_variant_access() { - _THROW(bad_variant_access{}); -} - _STD_END #pragma pop_macro("new") diff --git a/stl/inc/variant b/stl/inc/variant index 6c78314cec3..8d97c92bbdb 100644 --- a/stl/inc/variant +++ b/stl/inc/variant @@ -1175,6 +1175,27 @@ private: } }; +_EXPORT_STD class bad_variant_access + : public exception { // exception for visit of a valueless variant or get on a variant with index() != I +public: + bad_variant_access() noexcept = default; + + _NODISCARD const char* __CLR_OR_THIS_CALL what() const noexcept override { + return "bad variant access"; + } + +#if !_HAS_EXCEPTIONS +protected: + void _Doraise() const override { // perform class-specific exception handling + _RAISE(*this); + } +#endif // ^^^ !_HAS_EXCEPTIONS ^^^ +}; + +[[noreturn]] inline void _Throw_bad_variant_access() { + _THROW(bad_variant_access{}); +} + _EXPORT_STD template _NODISCARD constexpr bool holds_alternative(const variant<_Types...>& _Var) noexcept { // true iff _Var holds alternative _Ty From 3618182ece3c20d0a42d2dbbafc166f3f221c374 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:55:10 +0800 Subject: [PATCH 3/8] move `_Throw_bad_array_new_length` to `` --- stl/inc/exception | 4 ---- stl/inc/xmemory | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/inc/exception b/stl/inc/exception index b48d33e94a7..41b4101ed6d 100644 --- a/stl/inc/exception +++ b/stl/inc/exception @@ -327,10 +327,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()) {} diff --git a/stl/inc/xmemory b/stl/inc/xmemory index 75c315c4477..a612d99d103 100644 --- a/stl/inc/xmemory +++ b/stl/inc/xmemory @@ -60,6 +60,10 @@ template _INLINE_VAR constexpr bool _Nothrow_compare = noexcept( static_cast(_STD declval()(_STD declval(), _STD declval()))); +[[noreturn]] inline void _Throw_bad_array_new_length() { + _THROW(bad_array_new_length{}); +} + template _NODISCARD constexpr size_t _Get_size_of_n(const size_t _Count) { constexpr bool _Overflow_is_possible = _Ty_size > 1; From 8abcc7b073774ad757304c9185cca5899262a149 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:41:06 +0800 Subject: [PATCH 4/8] merge `exception_ptr::_Current_exception` --- stl/inc/exception | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/stl/inc/exception b/stl/inc/exception index 41b4101ed6d..637b1822c95 100644 --- a/stl/inc/exception +++ b/stl/inc/exception @@ -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) { From f825956719bb9aa00209fd501ed7de07a9cc42c7 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:49:43 +0800 Subject: [PATCH 5/8] simplify `_With_nested` --- stl/inc/exception | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stl/inc/exception b/stl/inc/exception index 637b1822c95..c327e781705 100644 --- a/stl/inc/exception +++ b/stl/inc/exception @@ -347,9 +347,10 @@ private: exception_ptr _Exc; }; -template -struct _With_nested : _Uty, nested_exception { // glue user exception to nested_exception - explicit _With_nested(_Ty&& _Arg) +template +struct _With_nested_v2 : _Uty, nested_exception { // glue user exception to nested_exception + template + explicit _With_nested_v2(_Ty&& _Arg) : _Uty(_STD forward<_Ty>(_Arg)), nested_exception() {} // store user exception and current_exception() }; @@ -360,7 +361,7 @@ _EXPORT_STD template if constexpr (is_class_v<_Uty> && !is_base_of_v && !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 From bad76318ee80d8299277c0423caa7a2c492d96d0 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Thu, 17 Aug 2023 11:48:34 +0800 Subject: [PATCH 6/8] Revert "move `bad_variant_access` back to ``" This reverts commit 12bfbb7565cdb35fbb5b7a63f30b9931ed755cb0. --- stl/inc/exception | 21 +++++++++++++++++++++ stl/inc/variant | 21 --------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/stl/inc/exception b/stl/inc/exception index c327e781705..afda3fb4b21 100644 --- a/stl/inc/exception +++ b/stl/inc/exception @@ -389,6 +389,27 @@ _EXPORT_STD template void rethrow_if_nested(const _Ty&) = delete; // requires /GR option #endif // ^^^ !defined(_CPPRTTI) ^^^ +_EXPORT_STD class bad_variant_access + : public exception { // exception for visit of a valueless variant or get on a variant with index() != I +public: + bad_variant_access() noexcept = default; + + _NODISCARD const char* __CLR_OR_THIS_CALL what() const noexcept override { + return "bad variant access"; + } + +#if !_HAS_EXCEPTIONS +protected: + void _Doraise() const override { // perform class-specific exception handling + _RAISE(*this); + } +#endif // ^^^ !_HAS_EXCEPTIONS ^^^ +}; + +[[noreturn]] inline void _Throw_bad_variant_access() { + _THROW(bad_variant_access{}); +} + _STD_END #pragma pop_macro("new") diff --git a/stl/inc/variant b/stl/inc/variant index 8d97c92bbdb..6c78314cec3 100644 --- a/stl/inc/variant +++ b/stl/inc/variant @@ -1175,27 +1175,6 @@ private: } }; -_EXPORT_STD class bad_variant_access - : public exception { // exception for visit of a valueless variant or get on a variant with index() != I -public: - bad_variant_access() noexcept = default; - - _NODISCARD const char* __CLR_OR_THIS_CALL what() const noexcept override { - return "bad variant access"; - } - -#if !_HAS_EXCEPTIONS -protected: - void _Doraise() const override { // perform class-specific exception handling - _RAISE(*this); - } -#endif // ^^^ !_HAS_EXCEPTIONS ^^^ -}; - -[[noreturn]] inline void _Throw_bad_variant_access() { - _THROW(bad_variant_access{}); -} - _EXPORT_STD template _NODISCARD constexpr bool holds_alternative(const variant<_Types...>& _Var) noexcept { // true iff _Var holds alternative _Ty From ee2508f3fc82a23dbb33d56f329476ccad50f984 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:36:48 +0800 Subject: [PATCH 7/8] Revert "move `monostate` back to ``" This reverts commit b4aecea3f6d80daaa9fb63da9a2527973abbee7e. --- stl/inc/format | 8 +++----- stl/inc/variant | 2 -- stl/inc/xutility | 4 ++++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/stl/inc/format b/stl/inc/format index 1a7584baf1d..5b976f2f5d8 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -688,8 +688,6 @@ class basic_format_args; _FMT_P2286_BEGIN template struct _Format_handler; - -struct _Monostate {}; _FMT_P2286_END _EXPORT_STD template @@ -820,7 +818,7 @@ private: _Basic_format_arg_type _Active_state = _Basic_format_arg_type::_None; union { - _Monostate _No_state{}; + monostate _No_state = monostate{}; int _Int_state; unsigned int _UInt_state; long long _Long_long_state; @@ -2419,7 +2417,7 @@ _EXPORT_STD using wformat_context = basic_format_context<_Fmt_wit, wchar_t>; _FMT_P2286_BEGIN template -_NODISCARD _OutputIt _Fmt_write(_OutputIt _Out, _Monostate) { +_NODISCARD _OutputIt _Fmt_write(_OutputIt _Out, monostate) { _STL_INTERNAL_CHECK(false); return _Out; } @@ -2688,7 +2686,7 @@ _NODISCARD _OutputIt _Write_separated_integer(const char* _First, const char* co } template -_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; } diff --git a/stl/inc/variant b/stl/inc/variant index 6c78314cec3..b1da693c42d 100644 --- a/stl/inc/variant +++ b/stl/inc/variant @@ -1655,8 +1655,6 @@ 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; } diff --git a/stl/inc/xutility b/stl/inc/xutility index e4cb6f93901..880293a0d71 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -7170,6 +7170,10 @@ _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) { From 12b6cbf3859178119b9f601d52a9b75ed763b4f9 Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Thu, 31 Aug 2023 23:24:06 +0800 Subject: [PATCH 8/8] replace `_THROW(format_error(...` with `_Throw_format_error(...` --- stl/inc/chrono | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/stl/inc/chrono b/stl/inc/chrono index f8cb5a98746..d57acea0a2e 100644 --- a/stl/inc/chrono +++ b/stl/inc/chrono @@ -5293,14 +5293,14 @@ namespace chrono { if constexpr (_Is_specialization_v<_Ty, duration>) { if constexpr (!treat_as_floating_point_v) { 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."); } } @@ -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) {