From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1720) id 12BE43858C66; Thu, 11 Jan 2024 20:55:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12BE43858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705006542; bh=Rvn+3IwEE7FA8TIt8Z6AEiCYZZrPjCIdRLVx4/jMGeE=; h=From:To:Subject:Date:From; b=FYwJ0EHYbgAb5okw9LDF5zgLN3uO5o9DYdzZbjP+NXN9ZKk47MLy2UFdW0Xem1nBm hWa92CEtQRBMgJ1UWUfb0O4UgpU5/hWMA1C9PG2pAD/imPcvN6wJfYTLzCGuQwdu9Z q2dFBcPClDN1Kpl1qSwBXehy/bCQ/8G68YU53bTc= 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-8212] libstdc++: [_GLIBCXX_DEBUG] Fix assignment of value-initialized iterator [PR112477] 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: 29809d2332b402302b1677ca3c6df8ce44c15341 X-Git-Newrev: ffc5684a4d3d3c457e5d311e7088f3487cf5083e Message-Id: <20240111205542.12BE43858C66@sourceware.org> Date: Thu, 11 Jan 2024 20:55:42 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ffc5684a4d3d3c457e5d311e7088f3487cf5083e commit r13-8212-gffc5684a4d3d3c457e5d311e7088f3487cf5083e Author: François Dumont Date: Wed Jan 10 19:06:48 2024 +0100 libstdc++: [_GLIBCXX_DEBUG] Fix assignment of value-initialized iterator [PR112477] Now that _M_Detach do not reset iterator _M_version value we need to reset it when the iterator is attached to a new sequence. Even if this sequence is null like when assigning a value-initialized iterator. In this case _M_version shall be reset to 0. libstdc++-v3/ChangeLog: PR libstdc++/112477 * src/c++11/debug.cc (_Safe_iterator_base::_M_attach): Reset _M_version to 0 if attaching to null sequence. (_Safe_iterator_base::_M_attach_single): Likewise. (_Safe_local_iterator_base::_M_attach): Likewise. (_Safe_local_iterator_base::_M_attach_single): Likewise. * testsuite/23_containers/map/debug/112477.cc: New test case. Reviewed-by: Jonathan Wakely Diff: --- libstdc++-v3/src/c++11/debug.cc | 8 ++++++++ .../testsuite/23_containers/map/debug/112477.cc | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc index bb0d0db6679..cb2cbf9d312 100644 --- a/libstdc++-v3/src/c++11/debug.cc +++ b/libstdc++-v3/src/c++11/debug.cc @@ -437,6 +437,8 @@ namespace __gnu_debug _M_version = _M_sequence->_M_version; _M_sequence->_M_attach(this, __constant); } + else + _M_version = 0; } void @@ -452,6 +454,8 @@ namespace __gnu_debug _M_version = _M_sequence->_M_version; _M_sequence->_M_attach_single(this, __constant); } + else + _M_version = 0; } void @@ -528,6 +532,8 @@ namespace __gnu_debug _M_version = _M_sequence->_M_version; _M_get_container()->_M_attach_local(this, __constant); } + else + _M_version = 0; } void @@ -543,6 +549,8 @@ namespace __gnu_debug _M_version = _M_sequence->_M_version; _M_get_container()->_M_attach_local_single(this, __constant); } + else + _M_version = 0; } void diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/112477.cc b/libstdc++-v3/testsuite/23_containers/map/debug/112477.cc new file mode 100644 index 00000000000..bde613b8905 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/debug/112477.cc @@ -0,0 +1,20 @@ +// { dg-do run { target c++11 } } +// { dg-require-debug-mode "" } + +// PR libstdc++/112477 + +#include + +int main() +{ + using M = std::map; + using I = M::iterator; + + M map{ {1, 1}, {2, 2} }; + + I it1 = map.begin(); + it1 = I{}; + + I it2{}; + (void)(it1 == it2); +}