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-7151] libstdc++: [_GLIBCXX_DEBUG] Fix assignment of value-initialized iterator [PR112477]
Date: Thu, 11 Jan 2024 18:31:10 +0000 (GMT)	[thread overview]
Message-ID: <20240111183111.02E52386F432@sourceware.org> (raw)

https://gcc.gnu.org/g:46afbeb81414302829fbf10c107e5466a3cf44d7

commit r14-7151-g46afbeb81414302829fbf10c107e5466a3cf44d7
Author: François Dumont <fdumont@gcc.gnu.org>
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 sequencer is null when
    assigning a value-initialized iterator. In this case _M_version shall be resetted 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 <jwakely@redhat.com>

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 54092f541ba..5d6bb5b7547 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 <map>
+
+int main()
+{
+  using M = std::map<int, int>;
+  using I = M::iterator;
+
+  M map{ {1, 1}, {2, 2} };
+
+  I it1 = map.begin();
+  it1 = I{};
+
+  I it2{};
+  (void)(it1 == it2);
+}

                 reply	other threads:[~2024-01-11 18:31 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=20240111183111.02E52386F432@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).