* Re: [Bug libstdc++/112477] [13/14 Regression] Assignment of value-initialized iterators differs from value-initialization
[not found] ` <bug-112477-19885-GQRgTWr6Ee@http.gcc.gnu.org/bugzilla/>
@ 2024-01-10 18:28 ` François Dumont
2024-01-11 18:02 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: François Dumont @ 2024-01-10 18:28 UTC (permalink / raw)
To: libstdc++; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1449 bytes --]
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 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.
Tested under Linux x64 _GLIBCXX_DEBUG mode.
Ok to commit and backport to gcc 13 ?
François
On 09/01/2024 22:47, fdumont at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112477
>
> François Dumont <fdumont at gcc dot gnu.org> changed:
>
> What |Removed |Added
> ----------------------------------------------------------------------------
> Assignee|unassigned at gcc dot gnu.org |fdumont at gcc dot gnu.org
>
> --- Comment #8 from François Dumont <fdumont at gcc dot gnu.org> ---
> Hi
> I'm going to have a look but if you wish to contribute do not hesitate.
> Thanks for the report.
>
[-- Attachment #2: pr112477_patch.txt --]
[-- Type: text/plain, Size: 1538 bytes --]
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 <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);
+}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Bug libstdc++/112477] [13/14 Regression] Assignment of value-initialized iterators differs from value-initialization
2024-01-10 18:28 ` [Bug libstdc++/112477] [13/14 Regression] Assignment of value-initialized iterators differs from value-initialization François Dumont
@ 2024-01-11 18:02 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2024-01-11 18:02 UTC (permalink / raw)
To: François Dumont; +Cc: libstdc++, gcc-patches
On Wed, 10 Jan 2024 at 18:28, François Dumont <frs.dumont@gmail.com> wrote:
>
> 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 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.
>
> Tested under Linux x64 _GLIBCXX_DEBUG mode.
>
> Ok to commit and backport to gcc 13 ?
Yes please - thanks for the quick fix.
>
> François
>
> On 09/01/2024 22:47, fdumont at gcc dot gnu.org wrote:
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112477
> >
> > François Dumont <fdumont at gcc dot gnu.org> changed:
> >
> > What |Removed |Added
> > ----------------------------------------------------------------------------
> > Assignee|unassigned at gcc dot gnu.org |fdumont at gcc dot gnu.org
> >
> > --- Comment #8 from François Dumont <fdumont at gcc dot gnu.org> ---
> > Hi
> > I'm going to have a look but if you wish to contribute do not hesitate.
> > Thanks for the report.
> >
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-11 18:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-112477-19885@http.gcc.gnu.org/bugzilla/>
[not found] ` <bug-112477-19885-GQRgTWr6Ee@http.gcc.gnu.org/bugzilla/>
2024-01-10 18:28 ` [Bug libstdc++/112477] [13/14 Regression] Assignment of value-initialized iterators differs from value-initialization François Dumont
2024-01-11 18:02 ` Jonathan Wakely
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).