public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Francois Dumont <fdumont@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-9507] libstdc++: Implement N3644 on _Safe_iterator<> [PR114316] Date: Sun, 17 Mar 2024 15:42:48 +0000 (GMT) [thread overview] Message-ID: <20240317154248.2F0FD3858D37@sourceware.org> (raw) https://gcc.gnu.org/g:07fad7a7fc245369989e9ca746728ea78b924715 commit r14-9507-g07fad7a7fc245369989e9ca746728ea78b924715 Author: François Dumont <fdumont@gcc.gnu.org> 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<difference_type, _Distance_precision>& __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<difference_type, _Distance_precision>& __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 <set> +#include <algorithm> + +#include <testsuite_hooks.h> + +int main() +{ + std::set<int>::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 <vector> +#include <algorithm> + +#include <testsuite_hooks.h> + +int main() +{ + std::vector<int>::iterator it{}; + VERIFY( std::find(it, it, 0) == it ); + return 0; +}
reply other threads:[~2024-03-17 15:42 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240317154248.2F0FD3858D37@sourceware.org \ --to=fdumont@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).