public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9525] libstdc++: Fix N3344 behavior on _Safe_iterator::_M_can_advance
@ 2024-03-18 21:32 Francois Dumont
  0 siblings, 0 replies; only message in thread
From: Francois Dumont @ 2024-03-18 21:32 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

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

commit r14-9525-gdda96a9d942d73a587e174dd5efe061208a195af
Author: François Dumont <fdumont@gcc.gnu.org>
Date:   Sun Mar 17 19:06:55 2024 +0100

    libstdc++: Fix N3344 behavior on _Safe_iterator::_M_can_advance
    
    We shall be able to advance from a 0 offset a value-initialized iterator.
    
    libstdc++-v3/ChangeLog:
    
            * include/debug/safe_iterator.tcc (_Safe_iterator<>::_M_can_advance):
            Accept 0 offset advance on value-initialized iterator.
            * testsuite/23_containers/vector/debug/n3644.cc: New test case.

Diff:
---
 libstdc++-v3/include/debug/safe_iterator.tcc             |  3 +++
 .../testsuite/23_containers/vector/debug/n3644.cc        | 16 ++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/libstdc++-v3/include/debug/safe_iterator.tcc b/libstdc++-v3/include/debug/safe_iterator.tcc
index 4b2baf2980e..deaa84d0a1f 100644
--- a/libstdc++-v3/include/debug/safe_iterator.tcc
+++ b/libstdc++-v3/include/debug/safe_iterator.tcc
@@ -86,6 +86,9 @@ namespace __gnu_debug
     _Safe_iterator<_Iterator, _Sequence, _Category>::
     _M_can_advance(difference_type __n, bool __strict) const
     {
+      if (this->_M_value_initialized() && __n == 0)
+	return true;
+
       if (this->_M_singular())
 	return false;
 
diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/n3644.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/n3644.cc
new file mode 100644
index 00000000000..052c52f26b7
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/debug/n3644.cc
@@ -0,0 +1,16 @@
+// { dg-do run { target c++11 } }
+// { dg-require-debug-mode "" }
+
+#include <vector>
+#include <algorithm>
+
+#include <testsuite_hooks.h>
+
+int main()
+{
+  std::vector<int>::iterator it{};
+  auto cpy = it;
+  std::advance(it, 0);
+  VERIFY( it == cpy );
+  return 0;
+}

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

only message in thread, other threads:[~2024-03-18 21:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-18 21:32 [gcc r14-9525] libstdc++: Fix N3344 behavior on _Safe_iterator::_M_can_advance Francois Dumont

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).