https://gcc.gnu.org/g:ac9fec014df8d75c2185981c9d191d1080e98094
commit r16-404-gac9fec014df8d75c2185981c9d191d1080e98094 Author: Jonathan Wakely <jwak...@redhat.com> Date: Thu May 1 22:56:56 2025 +0100 libstdc++: Add noexcept to some std::counted_iterator operations This was inspired by LWG 4245 but goes further. Anything which only reads or writes the _M_length member can be noexcept. That member is an iterator difference_type which means it's a signed integer type or the __max_diff_type integer-like class type, so all arithmetic and comparisons are non-throwing. libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (counted_iterator): Add noexcept to friend operators which only access the _M_length member. Reviewed-by: Tomasz KamiĆski <tkami...@redhat.com> Diff: --- libstdc++-v3/include/bits/stl_iterator.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index bed72955d0c4..478a98fe8a4f 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -2511,17 +2511,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION [[nodiscard]] friend constexpr iter_difference_t<_It2> operator-(const counted_iterator& __x, - const counted_iterator<_It2>& __y) + const counted_iterator<_It2>& __y) noexcept { return __y._M_length - __x._M_length; } [[nodiscard]] friend constexpr iter_difference_t<_It> - operator-(const counted_iterator& __x, default_sentinel_t) + operator-(const counted_iterator& __x, default_sentinel_t) noexcept { return -__x._M_length; } [[nodiscard]] friend constexpr iter_difference_t<_It> - operator-(default_sentinel_t, const counted_iterator& __y) + operator-(default_sentinel_t, const counted_iterator& __y) noexcept { return __y._M_length; } constexpr counted_iterator& @@ -2548,19 +2548,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION [[nodiscard]] friend constexpr bool operator==(const counted_iterator& __x, - const counted_iterator<_It2>& __y) + const counted_iterator<_It2>& __y) noexcept { return __x._M_length == __y._M_length; } [[nodiscard]] friend constexpr bool - operator==(const counted_iterator& __x, default_sentinel_t) + operator==(const counted_iterator& __x, default_sentinel_t) noexcept { return __x._M_length == 0; } template<common_with<_It> _It2> [[nodiscard]] friend constexpr strong_ordering operator<=>(const counted_iterator& __x, - const counted_iterator<_It2>& __y) + const counted_iterator<_It2>& __y) noexcept { return __y._M_length <=> __x._M_length; } [[nodiscard]]