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 r13-8470] libstdc++: Fix _Safe_local_iterator<>::_M_valid_range
Date: Wed, 20 Mar 2024 05:40:08 +0000 (GMT)	[thread overview]
Message-ID: <20240320054008.CBAFD3858CD1@sourceware.org> (raw)

https://gcc.gnu.org/g:86183487993315214091d593334893a883954f17

commit r13-8470-g86183487993315214091d593334893a883954f17
Author: François Dumont <fdumont@gcc.gnu.org>
Date:   Sun Mar 17 17:30:58 2024 +0100

    libstdc++: Fix _Safe_local_iterator<>::_M_valid_range
    
    Unordered container local_iterator range shall not contain any singular
    iterator unless both iterators are both value-initialized.
    
    libstdc++-v3/ChangeLog:
    
            * include/debug/safe_local_iterator.tcc
            (_Safe_local_iterator::_M_valid_range): Add _M_value_initialized and
            _M_singular checks.
            * testsuite/23_containers/unordered_set/debug/114316.cc: New test case.
    
    (cherry picked from commit 5f6e0853c30fec72d977afaa6f7a5633a8d910be)

Diff:
---
 libstdc++-v3/include/debug/safe_local_iterator.tcc |  8 ++++++-
 .../23_containers/unordered_set/debug/114316.cc    | 28 ++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/debug/safe_local_iterator.tcc b/libstdc++-v3/include/debug/safe_local_iterator.tcc
index 6fba344f16a..2444f41bb85 100644
--- a/libstdc++-v3/include/debug/safe_local_iterator.tcc
+++ b/libstdc++-v3/include/debug/safe_local_iterator.tcc
@@ -78,7 +78,13 @@ namespace __gnu_debug
     _M_valid_range(const _Safe_local_iterator& __rhs,
 		std::pair<difference_type, _Distance_precision>& __dist) const
     {
-      if (!_M_can_compare(__rhs))
+      if (_M_value_initialized() && __rhs._M_value_initialized())
+	{
+	  __dist = { 0, __dp_exact };
+	  return true;
+	}
+
+      if (_M_singular() || __rhs._M_singular() || !_M_can_compare(__rhs))
 	return false;
 
       if (bucket() != __rhs.bucket())
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/114316.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/114316.cc
new file mode 100644
index 00000000000..41b649a9cbd
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/114316.cc
@@ -0,0 +1,28 @@
+// { dg-do run { target c++11 } }
+// { dg-require-debug-mode "" }
+
+// PR libstdc++/114316
+
+#include <unordered_set>
+#include <algorithm>
+
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  std::unordered_set<int>::iterator it{};
+  VERIFY( std::find(it, it, 0) == it );
+}
+
+void test02()
+{
+  std::unordered_set<int>::local_iterator it{};
+  VERIFY( std::find(it, it, 0) == it );
+}
+
+int main()
+{
+  test01();
+  test02();
+  return 0;
+}

                 reply	other threads:[~2024-03-20  5:40 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=20240320054008.CBAFD3858CD1@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: link
Be 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).