From 56a1ad84c83d57d6de286506465b4622001674ee Mon Sep 17 00:00:00 2001 From: PhiliaTheCat <2787974051@qq.com> Date: Sat, 2 Dec 2023 10:31:15 +0800 Subject: [PATCH 1/3] : `ranges::_Ssize_fn::operator()` should have a noexcept-specifier Fixes #4107 --- stl/inc/xutility | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stl/inc/xutility b/stl/inc/xutility index 2f276896073..c64390dc54c 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -646,7 +646,7 @@ namespace ranges { public: template requires (_Choice<_Ty>._Strategy != _St::_None) - _NODISCARD constexpr decltype(auto) operator()(_Ty&& _Val) const noexcept(_Choice<_Ty>._No_throw) { + _NODISCARD constexpr decltype(auto) operator()(_Ty && _Val) const noexcept(_Choice<_Ty>._No_throw) { constexpr _St _Strat = _Choice<_Ty>._Strategy; if constexpr (_Strat == _St::_Custom) { @@ -1625,7 +1625,8 @@ public: template _BidIt2> friend constexpr void iter_swap(const reverse_iterator& _Left, const reverse_iterator<_BidIt2>& _Right) noexcept( - is_nothrow_copy_constructible_v<_BidIt>&& is_nothrow_copy_constructible_v<_BidIt2>&& noexcept( + is_nothrow_copy_constructible_v<_BidIt> + && is_nothrow_copy_constructible_v<_BidIt2>&& noexcept( _RANGES iter_swap(--_STD declval<_BidIt&>(), --_STD declval<_BidIt2&>()))) { auto _LTmp = _Left.current; auto _RTmp = _Right.base(); @@ -3353,7 +3354,7 @@ namespace ranges { class _Ssize_fn { public: template - _NODISCARD constexpr auto operator()(_Rng&& _Range) const + _NODISCARD constexpr auto operator()(_Rng&& _Range) const noexcept requires requires { _RANGES size(_Range); } { using _Sty = _Make_signed_like_t; @@ -5137,7 +5138,7 @@ _INLINE_VAR constexpr bool _Is_pointer_address_comparable = #pragma warning(push) #pragma warning(disable : 4806) // no value of type 'bool' promoted to type 'char' can equal the given constant template && is_integral_v<_Elem2>> + bool = sizeof(_Elem1) == sizeof(_Elem2) && is_integral_v<_Elem1> && is_integral_v<_Elem2>> _INLINE_VAR constexpr bool _Can_memcmp_elements = is_same_v<_Elem1, bool> || is_same_v<_Elem2, bool> || static_cast<_Elem1>(-1) == static_cast<_Elem2>(-1); #pragma warning(pop) From d9618d331dae9fcf11ac69fe16851fbcf2ff8963 Mon Sep 17 00:00:00 2001 From: PhiliaTheCat <2787974051@qq.com> Date: Sat, 2 Dec 2023 10:57:02 +0800 Subject: [PATCH 2/3] Formatting --- stl/inc/xutility | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/stl/inc/xutility b/stl/inc/xutility index c64390dc54c..16d1db3e350 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -646,7 +646,7 @@ namespace ranges { public: template requires (_Choice<_Ty>._Strategy != _St::_None) - _NODISCARD constexpr decltype(auto) operator()(_Ty && _Val) const noexcept(_Choice<_Ty>._No_throw) { + _NODISCARD constexpr decltype(auto) operator()(_Ty&& _Val) const noexcept(_Choice<_Ty>._No_throw) { constexpr _St _Strat = _Choice<_Ty>._Strategy; if constexpr (_Strat == _St::_Custom) { @@ -1625,8 +1625,7 @@ public: template _BidIt2> friend constexpr void iter_swap(const reverse_iterator& _Left, const reverse_iterator<_BidIt2>& _Right) noexcept( - is_nothrow_copy_constructible_v<_BidIt> - && is_nothrow_copy_constructible_v<_BidIt2>&& noexcept( + is_nothrow_copy_constructible_v<_BidIt>&& is_nothrow_copy_constructible_v<_BidIt2>&& noexcept( _RANGES iter_swap(--_STD declval<_BidIt&>(), --_STD declval<_BidIt2&>()))) { auto _LTmp = _Left.current; auto _RTmp = _Right.base(); @@ -5138,7 +5137,7 @@ _INLINE_VAR constexpr bool _Is_pointer_address_comparable = #pragma warning(push) #pragma warning(disable : 4806) // no value of type 'bool' promoted to type 'char' can equal the given constant template && is_integral_v<_Elem2>> + bool = sizeof(_Elem1) == sizeof(_Elem2) && is_integral_v<_Elem1>&& is_integral_v<_Elem2>> _INLINE_VAR constexpr bool _Can_memcmp_elements = is_same_v<_Elem1, bool> || is_same_v<_Elem2, bool> || static_cast<_Elem1>(-1) == static_cast<_Elem2>(-1); #pragma warning(pop) From 80a72a7b6adcf45f7b46907efa9bbf2c3cfcd7a4 Mon Sep 17 00:00:00 2001 From: PhiliaTheCat <2787974051@qq.com> Date: Sat, 2 Dec 2023 19:43:44 +0800 Subject: [PATCH 3/3] Add Static Assert and Conditional Non-Exception Throwing specifier --- stl/inc/xutility | 2 +- tests/std/tests/P0896R4_ranges_range_machinery/test.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/stl/inc/xutility b/stl/inc/xutility index 16d1db3e350..70b8e8e60e1 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -3353,7 +3353,7 @@ namespace ranges { class _Ssize_fn { public: template - _NODISCARD constexpr auto operator()(_Rng&& _Range) const noexcept + _NODISCARD constexpr auto operator()(_Rng&& _Range) const noexcept(noexcept(_RANGES size(_Range))) requires requires { _RANGES size(_Range); } { using _Sty = _Make_signed_like_t; diff --git a/tests/std/tests/P0896R4_ranges_range_machinery/test.cpp b/tests/std/tests/P0896R4_ranges_range_machinery/test.cpp index 176e93fae42..86b2371cec1 100644 --- a/tests/std/tests/P0896R4_ranges_range_machinery/test.cpp +++ b/tests/std/tests/P0896R4_ranges_range_machinery/test.cpp @@ -1529,6 +1529,7 @@ namespace nothrow_testing { STATIC_ASSERT(noexcept(ranges::crend(t)) == Nothrow); STATIC_ASSERT(noexcept(ranges::empty(t)) == Nothrow); STATIC_ASSERT(noexcept(ranges::size(t)) == Nothrow); + STATIC_ASSERT(noexcept(ranges::ssize(t)) == Nothrow); STATIC_ASSERT(noexcept(ranges::data(t)) == Nothrow); STATIC_ASSERT(noexcept(ranges::cdata(t)) == Nothrow);