From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1720) id 2F0FD3858D37; Sun, 17 Mar 2024 15:42:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F0FD3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710690168; bh=dD6rOaxuf2fChXi3Gf89RtdZXqEWVaKv3KqGWa7O1XM=; h=From:To:Subject:Date:From; b=SzVRb2L3roFyYe+ijPu0xDA7CrwNRrG0LyUsPsF6gx8B41xzOY1aWA/mVx1lwobXd lt2Cg9RKzAOaMyT1xfUCLXP+g/7Dj29Ua4C1tvnfnVcSO1eRHHYfhZcCii0J4vDNpc f55Lblffof1svUm0vYZxA4Unj0pOD6gQEvOv0mek= 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 r14-9507] libstdc++: Implement N3644 on _Safe_iterator<> [PR114316] X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Git-Refname: refs/heads/master X-Git-Oldrev: f065c582d9c8e0a4fee7ee563c584ee3b1975bea X-Git-Newrev: 07fad7a7fc245369989e9ca746728ea78b924715 Message-Id: <20240317154248.2F0FD3858D37@sourceware.org> Date: Sun, 17 Mar 2024 15:42:48 +0000 (GMT) List-Id: https://gcc.gnu.org/g:07fad7a7fc245369989e9ca746728ea78b924715 commit r14-9507-g07fad7a7fc245369989e9ca746728ea78b924715 Author: François Dumont Date: Thu Mar 14 22:13:57 2024 +0100 libstdc++: Implement N3644 on _Safe_iterator<> [PR114316] Consider range of value-initialized iterators as valid and empty. libstdc++-v3/ChangeLog: PR libstdc++/114316 * include/debug/safe_iterator.tcc (_Safe_iterator<>::_M_valid_range): First check if both iterators are value-initialized before checking if singular. * testsuite/23_containers/set/debug/114316.cc: New test case. * testsuite/23_containers/vector/debug/114316.cc: New test case. Diff: --- libstdc++-v3/include/debug/safe_iterator.tcc | 12 ++++++++++++ libstdc++-v3/testsuite/23_containers/set/debug/114316.cc | 16 ++++++++++++++++ .../testsuite/23_containers/vector/debug/114316.cc | 16 ++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/libstdc++-v3/include/debug/safe_iterator.tcc b/libstdc++-v3/include/debug/safe_iterator.tcc index a8b24233e85..4b2baf2980e 100644 --- a/libstdc++-v3/include/debug/safe_iterator.tcc +++ b/libstdc++-v3/include/debug/safe_iterator.tcc @@ -194,6 +194,12 @@ namespace __gnu_debug std::pair& __dist, bool __check_dereferenceable) const { + if (_M_value_initialized() && __rhs._M_value_initialized()) + { + __dist = std::make_pair(0, __dp_exact); + return true; + } + if (_M_singular() || __rhs._M_singular() || !_M_can_compare(__rhs)) return false; @@ -218,6 +224,12 @@ namespace __gnu_debug std::pair& __dist) const { + if (this->_M_value_initialized() && __rhs._M_value_initialized()) + { + __dist = std::make_pair(0, __dp_exact); + return true; + } + if (this->_M_singular() || __rhs._M_singular() || !this->_M_can_compare(__rhs)) return false; diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/114316.cc b/libstdc++-v3/testsuite/23_containers/set/debug/114316.cc new file mode 100644 index 00000000000..126ec89b5e0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/debug/114316.cc @@ -0,0 +1,16 @@ +// { dg-do run { target c++11 } } +// { dg-require-debug-mode "" } + +// PR libstdc++/114316 + +#include +#include + +#include + +int main() +{ + std::set::iterator it{}; + VERIFY( std::find(it, it, 0) == it ); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/114316.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/114316.cc new file mode 100644 index 00000000000..f211cf67b4c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/114316.cc @@ -0,0 +1,16 @@ +// { dg-do run { target c++11 } } +// { dg-require-debug-mode "" } + +// PR libstdc++/114316 + +#include +#include + +#include + +int main() +{ + std::vector::iterator it{}; + VERIFY( std::find(it, it, 0) == it ); + return 0; +}