]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix N3344 behavior on _Safe_iterator::_M_can_advance
authorFrançois Dumont <fdumont@gcc.gnu.org>
Sun, 17 Mar 2024 18:06:55 +0000 (19:06 +0100)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Mon, 18 Mar 2024 21:30:55 +0000 (22:30 +0100)
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.

libstdc++-v3/include/debug/safe_iterator.tcc
libstdc++-v3/testsuite/23_containers/vector/debug/n3644.cc [new file with mode: 0644]

index 4b2baf2980ede9d60ffec564dea9c5c90a322147..deaa84d0a1f3af37c09c3cb28c15c87d7b7a8670 100644 (file)
@@ -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 (file)
index 0000000..052c52f
--- /dev/null
@@ -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;
+}