From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1720) id ED0133858419; Wed, 20 Mar 2024 05:40:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED0133858419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710913213; bh=Q7qQAvt/7WauhixxplctkN6EoseNLSbP9byTzle/R0I=; h=From:To:Subject:Date:From; b=dP7yazZsFy69R6qXy7daEzufo3HKE7sBD5uB+12d/HhBLnz/HjBL84RJL0+wpe1/c 7hSmDQBQZCkYBni76Lvs92oMT11thq+n9ydJnMb/8KYuilaTrHUzOKIOMCnIElcDhg aBIETNZPX4vG0cYlITnOvJb7jhxJsatrM5j4tJ14= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Francois Dumont To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-8471] libstdc++: Fix N3344 behavior on _Safe_iterator::_M_can_advance X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 86183487993315214091d593334893a883954f17 X-Git-Newrev: 51e2f7a22e82a7cb2d321b82613b477b58ee4c60 Message-Id: <20240320054013.ED0133858419@sourceware.org> Date: Wed, 20 Mar 2024 05:40:13 +0000 (GMT) List-Id: https://gcc.gnu.org/g:51e2f7a22e82a7cb2d321b82613b477b58ee4c60 commit r13-8471-g51e2f7a22e82a7cb2d321b82613b477b58ee4c60 Author: François Dumont 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. (cherry picked from commit dda96a9d942d73a587e174dd5efe061208a195af) 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 2640fc8a473..4e213c4a0f6 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 +#include + +#include + +int main() +{ + std::vector::iterator it{}; + auto cpy = it; + std::advance(it, 0); + VERIFY( it == cpy ); + return 0; +}