From: "François Dumont" <frs.dumont@gmail.com>
To: Jonathan Wakely <jwakely.gcc@gmail.com>
Cc: Jonathan Wakely <jwakely@redhat.com>,
libstdc++ <libstdc++@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: _LIBCXX_DEBUG value initialized singular iterators assert failures in std algorithms [PR104316]
Date: Sun, 17 Mar 2024 19:14:16 +0100 [thread overview]
Message-ID: <4374668e-f7e9-4912-a8e6-a50710999d4b@gmail.com> (raw)
In-Reply-To: <a2ff35d2-00bf-4fb1-bda8-81d8e0544fce@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1865 bytes --]
I was a little bit too confident below. After review of all _M_singular
usages I found another necessary fix.
After this one for sure we will be able to define
__cpp_lib_null_iterators even in Debug mode.
libstdc++: Fix N3344 behavior on _Safe_iterator::_M_can_advance
We shall be able to advance from a 0 offset a value-initialized
iterator.
libstdc++-v3/ChangeLog:
* include/debug/safe_iterator.tcc
(_Safe_iterator<>::_M_can_advance):
Accept 0 offset advance on value-initialized iterator.
* testsuite/23_containers/vector/debug/n3644.cc: New test case.
Ok to commit ?
François
On 17/03/2024 17:52, François Dumont wrote:
>
>>
>> OK for trunk, thanks!
>>
>> I think this is OK to backport to 13 too.
>>
>> Maybe after this we can define the __cpp_lib_null_itetators macro for
>> debug mode?
>>
> After this fix of local_iterator I think we can indeed.
>
> In fact the added 11316.cc was already passing for
> unordered_set<>::local_iterator but simply because we were missing the
> singular check. Both issues solved with this patch.
>
> I found the version.def file to cleanup but no idea how to regenerate
> version.h from it so I'll let you do it, ok ?
>
> libstdc++: Fix _Safe_local_iterator<>::_M_valid_range
>
> Unordered container local_iterator range shall not contain any
> singular
> iterator unless both iterators are 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.
>
>
> Ok to commit ?
>
> François
[-- Attachment #2: n3344_patch.txt --]
[-- Type: text/plain, Size: 1088 bytes --]
diff --git a/libstdc++-v3/include/debug/safe_iterator.tcc b/libstdc++-v3/include/debug/safe_iterator.tcc
index 4b2baf2980e..deaa84d0a1f 100644
--- a/libstdc++-v3/include/debug/safe_iterator.tcc
+++ b/libstdc++-v3/include/debug/safe_iterator.tcc
@@ -86,6 +86,9 @@ namespace __gnu_debug
_Safe_iterator<_Iterator, _Sequence, _Category>::
_M_can_advance(difference_type __n, bool __strict) const
{
+ if (this->_M_value_initialized() && __n == 0)
+ return true;
+
if (this->_M_singular())
return false;
diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/n3644.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/n3644.cc
new file mode 100644
index 00000000000..052c52f26b7
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/debug/n3644.cc
@@ -0,0 +1,16 @@
+// { dg-do run { target c++11 } }
+// { dg-require-debug-mode "" }
+
+#include <vector>
+#include <algorithm>
+
+#include <testsuite_hooks.h>
+
+int main()
+{
+ std::vector<int>::iterator it{};
+ auto cpy = it;
+ std::advance(it, 0);
+ VERIFY( it == cpy );
+ return 0;
+}
next prev parent reply other threads:[~2024-03-17 18:14 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-11 20:07 _LIBCXX_DEBUG value initialized singular iterators assert failures in std algorithms Maciej Miera
2024-03-11 20:40 ` Jonathan Wakely
2024-03-12 0:54 ` Maciej Miera
2024-03-12 1:03 ` Jonathan Wakely
2024-03-12 9:52 ` Jonathan Wakely
2024-03-14 21:49 ` _LIBCXX_DEBUG value initialized singular iterators assert failures in std algorithms [PR104316] François Dumont
2024-03-16 12:16 ` François Dumont
2024-03-17 11:45 ` Jonathan Wakely
2024-03-17 16:52 ` François Dumont
2024-03-17 18:14 ` François Dumont [this message]
2024-03-18 7:45 ` Jonathan Wakely
2024-03-18 21:38 ` François Dumont
2024-03-19 9:31 ` Jonathan Wakely
2024-03-19 15:41 ` Jonathan Wakely
2024-03-20 5:59 ` François Dumont
2024-03-20 9:02 ` Jonathan Wakely
2024-03-20 18:10 ` François Dumont
2024-03-21 6:20 ` Jonathan Wakely
2024-03-18 7:45 ` Jonathan Wakely
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=4374668e-f7e9-4912-a8e6-a50710999d4b@gmail.com \
--to=frs.dumont@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jwakely.gcc@gmail.com \
--cc=jwakely@redhat.com \
--cc=libstdc++@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).