public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-3113] libstdc++: Enforce LWG 3472 preconditions on std::counted_iterator
@ 2020-09-10 16:09 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2020-09-10 16:09 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:afea21f9612545282db95872021d7587c9d5b0d4

commit r11-3113-gafea21f9612545282db95872021d7587c9d5b0d4
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 10 17:09:15 2020 +0100

    libstdc++: Enforce LWG 3472 preconditions on std::counted_iterator
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/stl_iterator.h (counted_iterator): Add assertions
            to check preconditions added by LWG 3472.

Diff:
---
 libstdc++-v3/include/bits/stl_iterator.h | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index da740e3732e..f29bae92706 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -2036,13 +2036,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       constexpr decltype(auto)
       operator*()
       noexcept(noexcept(*_M_current))
-      { return *_M_current; }
+      {
+	__glibcxx_assert( _M_length > 0 );
+	return *_M_current;
+      }
 
       constexpr decltype(auto)
       operator*() const
       noexcept(noexcept(*_M_current))
       requires __detail::__dereferenceable<const _It>
-      { return *_M_current; }
+      {
+	__glibcxx_assert( _M_length > 0 );
+	return *_M_current;
+      }
 
       constexpr counted_iterator&
       operator++()
@@ -2170,14 +2176,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       iter_move(const counted_iterator& __i)
       noexcept(noexcept(ranges::iter_move(__i._M_current)))
       requires input_iterator<_It>
-      { return ranges::iter_move(__i._M_current); }
+      {
+	__glibcxx_assert( __i._M_length > 0 );
+	return ranges::iter_move(__i._M_current);
+      }
 
       template<indirectly_swappable<_It> _It2>
 	friend constexpr void
 	iter_swap(const counted_iterator& __x,
 		  const counted_iterator<_It2>& __y)
 	noexcept(noexcept(ranges::iter_swap(__x._M_current, __y._M_current)))
-	{ ranges::iter_swap(__x._M_current, __y._M_current); }
+	{
+	  __glibcxx_assert( __x._M_length > 0 && __y._M_length > 0 );
+	  ranges::iter_swap(__x._M_current, __y._M_current);
+	}
 
     private:
       template<input_or_output_iterator _It2> friend class counted_iterator;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-10 16:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-10 16:09 [gcc r11-3113] libstdc++: Enforce LWG 3472 preconditions on std::counted_iterator Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).