From dda96a9d942d73a587e174dd5efe061208a195af Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Dumont?= Date: Sun, 17 Mar 2024 19:06:55 +0100 Subject: [PATCH] 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. --- libstdc++-v3/include/debug/safe_iterator.tcc | 3 +++ .../23_containers/vector/debug/n3644.cc | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 libstdc++-v3/testsuite/23_containers/vector/debug/n3644.cc diff --git a/libstdc++-v3/include/debug/safe_iterator.tcc b/libstdc++-v3/include/debug/safe_iterator.tcc index 4b2baf2980ed..deaa84d0a1f3 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 000000000000..052c52f26b7c --- /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 +#include + +#include + +int main() +{ + std::vector::iterator it{}; + auto cpy = it; + std::advance(it, 0); + VERIFY( it == cpy ); + return 0; +} -- 2.43.5