aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2025-05-01 22:56:56 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2025-05-06 13:00:44 +0100
commitac9fec014df8d75c2185981c9d191d1080e98094 (patch)
tree743fad196207464def73e1232cba6698d3e7420a
parent76c33109074b8e7cf6c326116b46792070122c7b (diff)
downloadgcc-ac9fec014df8d75c2185981c9d191d1080e98094.zip
gcc-ac9fec014df8d75c2185981c9d191d1080e98094.tar.gz
gcc-ac9fec014df8d75c2185981c9d191d1080e98094.tar.bz2
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 <tkaminsk@redhat.com>
-rw-r--r--libstdc++-v3/include/bits/stl_iterator.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index bed7295..478a98f 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]]