public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/116549] New: std::disable_sized_sentinel_for is missing specialisation for std::move_iterator
@ 2024-08-31 10:44 daidodo at gmail dot com
  2024-08-31 11:07 ` [Bug libstdc++/116549] " daidodo at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: daidodo at gmail dot com @ 2024-08-31 10:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116549

            Bug ID: 116549
           Summary: std::disable_sized_sentinel_for is missing
                    specialisation for std::move_iterator
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daidodo at gmail dot com
  Target Milestone: ---

Hi, the following code fail to compile:

```
// std=c++23

#include <iterator>

int main() {
    static_assert(not std::sized_sentinel_for<int*, int**>);
    using S = std::move_iterator<int*>;
    using I = std::move_iterator<int**>;
    static_assert(true == std::disable_sized_sentinel_for<S, I>); // error
}
```

When S is not a sized sentinel of I, we should not make std::move_iterator<S> a
sized sentinel for std::move_iterator<I>.

According to cppreference
(https://en.cppreference.com/w/cpp/iterator/move_iterator), there should be a
specialisation of std::disable_sized_sentinel_for:

```
template< class Iterator1, class Iterator2 >
    requires (!std::sized_sentinel_for<Iterator1, Iterator2>)
constexpr bool disable_sized_sentinel_for<
    std::move_iterator<Iterator1>,
    std::move_iterator<Iterator2>> = true;
```

But I couldn't find it in any of the current GCC source, especially
*libstdc++-v3/include/bits/stl_iterator.h* where std::move_iterator is defined.

Please confirm if it's a miss?

Thanks,
Zhao

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/116549] std::disable_sized_sentinel_for is missing specialisation for std::move_iterator
  2024-08-31 10:44 [Bug libstdc++/116549] New: std::disable_sized_sentinel_for is missing specialisation for std::move_iterator daidodo at gmail dot com
@ 2024-08-31 11:07 ` daidodo at gmail dot com
  2024-08-31 18:19 ` daniel.kruegler at googlemail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: daidodo at gmail dot com @ 2024-08-31 11:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116549

--- Comment #1 from Zhao Dai <daidodo at gmail dot com> ---
Just found a report in 2022: https://cplusplus.github.io/LWG/issue3736

Unfortunately, it's not resolved yet despite it seems an easy fix.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/116549] std::disable_sized_sentinel_for is missing specialisation for std::move_iterator
  2024-08-31 10:44 [Bug libstdc++/116549] New: std::disable_sized_sentinel_for is missing specialisation for std::move_iterator daidodo at gmail dot com
  2024-08-31 11:07 ` [Bug libstdc++/116549] " daidodo at gmail dot com
@ 2024-08-31 18:19 ` daniel.kruegler at googlemail dot com
  2024-09-01  1:37 ` daidodo at gmail dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2024-08-31 18:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116549

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler@googlemail.
                   |                            |com

--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(In reply to Zhao Dai from comment #1)
> Just found a report in 2022: https://cplusplus.github.io/LWG/issue3736
> 
> Unfortunately, it's not resolved yet despite it seems an easy fix.

Why do you think it is not resolved? The issue says that it was accepted in
Kona 2022 into the working paper and affects C++23.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/116549] std::disable_sized_sentinel_for is missing specialisation for std::move_iterator
  2024-08-31 10:44 [Bug libstdc++/116549] New: std::disable_sized_sentinel_for is missing specialisation for std::move_iterator daidodo at gmail dot com
  2024-08-31 11:07 ` [Bug libstdc++/116549] " daidodo at gmail dot com
  2024-08-31 18:19 ` daniel.kruegler at googlemail dot com
@ 2024-09-01  1:37 ` daidodo at gmail dot com
  2024-09-02 10:07 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: daidodo at gmail dot com @ 2024-09-01  1:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116549

--- Comment #3 from Zhao Dai <daidodo at gmail dot com> ---
Thanks for the reply!

I tested on Compiler Explorer (https://godbolt.org/z/EKxhvKoez, GCC trunk,
-std=c++23).

And
> I couldn't find it in any of the current GCC source, especially *libstdc++-v3/include/bits/stl_iterator.h* where std::move_iterator is defined.

https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/stl_iterator.h

Regards,
Zhao

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/116549] std::disable_sized_sentinel_for is missing specialisation for std::move_iterator
  2024-08-31 10:44 [Bug libstdc++/116549] New: std::disable_sized_sentinel_for is missing specialisation for std::move_iterator daidodo at gmail dot com
                   ` (2 preceding siblings ...)
  2024-09-01  1:37 ` daidodo at gmail dot com
@ 2024-09-02 10:07 ` redi at gcc dot gnu.org
  2024-09-02 10:09 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2024-09-02 10:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116549

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think there's some confusion in terminology. The issue has been "resolved" in
the C++ standard, but the resolution is not implemented in libstdc++ yet.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/116549] std::disable_sized_sentinel_for is missing specialisation for std::move_iterator
  2024-08-31 10:44 [Bug libstdc++/116549] New: std::disable_sized_sentinel_for is missing specialisation for std::move_iterator daidodo at gmail dot com
                   ` (3 preceding siblings ...)
  2024-09-02 10:07 ` redi at gcc dot gnu.org
@ 2024-09-02 10:09 ` redi at gcc dot gnu.org
  2024-09-02 10:22 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2024-09-02 10:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116549

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.4
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-09-02
           Keywords|                            |rejects-valid
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/116549] std::disable_sized_sentinel_for is missing specialisation for std::move_iterator
  2024-08-31 10:44 [Bug libstdc++/116549] New: std::disable_sized_sentinel_for is missing specialisation for std::move_iterator daidodo at gmail dot com
                   ` (4 preceding siblings ...)
  2024-09-02 10:09 ` redi at gcc dot gnu.org
@ 2024-09-02 10:22 ` redi at gcc dot gnu.org
  2024-09-02 11:25 ` daidodo at gmail dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2024-09-02 10:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116549

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Zhao Dai from comment #0)
> Hi, the following code fail to compile:
> 
> ```
> // std=c++23
> 
> #include <iterator>
> 
> int main() {
>     static_assert(not std::sized_sentinel_for<int*, int**>);
>     using S = std::move_iterator<int*>;
>     using I = std::move_iterator<int**>;
>     static_assert(true == std::disable_sized_sentinel_for<S, I>); // error
> }
> ```
> 
> When S is not a sized sentinel of I, we should not make
> std::move_iterator<S> a sized sentinel for std::move_iterator<I>.

We don't make it a sized sentinel though:

#include <iterator>
using S = std::move_iterator<int*>;
using I = std::move_iterator<int**>;
static_assert(not std::sized_sentinel_for<S, I>);
static_assert(not std::sized_sentinel_for<I, S>);

The way to tell if something is a sized sentinel is to test
std::sized_sentinel_for.

Testing std::disable_sized_sentinel_for is wrong. You cannot rely on that to
tell you if something is a sized sentinel. In the example above,
std::sentinel_for<S, I> is false, so 
std::disable_sized_sentinel_for is never needed.

The resolution to LWG issue 3736 says we should add that specialization anyway,
but I think it's redundant and not observable by any sensible code that uses
std::sized_sentinel_for correctly. (This was noted in the issue discussion.)

I'll add the disable_sized_sentinel_for specialization, because the standard
says we should define it. But your example code is not something that anybody
should ever write in real code.

> 
> According to cppreference
> (https://en.cppreference.com/w/cpp/iterator/move_iterator), there should be
> a specialisation of std::disable_sized_sentinel_for:
> 
> ```
> template< class Iterator1, class Iterator2 >
>     requires (!std::sized_sentinel_for<Iterator1, Iterator2>)
> constexpr bool disable_sized_sentinel_for<
>     std::move_iterator<Iterator1>,
>     std::move_iterator<Iterator2>> = true;
> ```
> 
> But I couldn't find it in any of the current GCC source, especially
> *libstdc++-v3/include/bits/stl_iterator.h* where std::move_iterator is
> defined.
> 
> Please confirm if it's a miss?
> 
> Thanks,
> Zhao

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/116549] std::disable_sized_sentinel_for is missing specialisation for std::move_iterator
  2024-08-31 10:44 [Bug libstdc++/116549] New: std::disable_sized_sentinel_for is missing specialisation for std::move_iterator daidodo at gmail dot com
                   ` (5 preceding siblings ...)
  2024-09-02 10:22 ` redi at gcc dot gnu.org
@ 2024-09-02 11:25 ` daidodo at gmail dot com
  2024-09-03 15:18 ` cvs-commit at gcc dot gnu.org
  2024-09-04 20:35 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: daidodo at gmail dot com @ 2024-09-02 11:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116549

--- Comment #6 from Zhao Dai <daidodo at gmail dot com> ---
Thanks for the explanation, Jonathan!

I agree that `sized_sentinel_for` is the right way to check sized sentinel.

From the source of `sized_sentinel_for`
(https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/iterator_concepts.h#L659),
my understanding is that `disable_sized_sentinel_for` is a "manual switch" for
sized sentinel. In that sense, it doesn't seem completely useless, though.

Anyway, thank you for picking this up!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/116549] std::disable_sized_sentinel_for is missing specialisation for std::move_iterator
  2024-08-31 10:44 [Bug libstdc++/116549] New: std::disable_sized_sentinel_for is missing specialisation for std::move_iterator daidodo at gmail dot com
                   ` (6 preceding siblings ...)
  2024-09-02 11:25 ` daidodo at gmail dot com
@ 2024-09-03 15:18 ` cvs-commit at gcc dot gnu.org
  2024-09-04 20:35 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-09-03 15:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116549

--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:819deae0a5bee079a7d5582fafaa098c26144ae8

commit r15-3423-g819deae0a5bee079a7d5582fafaa098c26144ae8
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Sep 2 11:29:13 2024 +0100

    libstdc++: Specialize std::disable_sized_sentinel_for for
std::move_iterator [PR116549]

    LWG 3736 added a partial specialization of this variable template for
    two std::move_iterator types. This is needed for the case where the
    types satisfy std::sentinel_for and are subtractable, but do not model
    the semantics requirements of std::sized_sentinel_for.

    libstdc++-v3/ChangeLog:

            PR libstdc++/116549
            * include/bits/stl_iterator.h (disable_sized_sentinel_for):
            Define specialization for two move_iterator types, as per LWG
            3736.
            * testsuite/24_iterators/move_iterator/lwg3736.cc: New test.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/116549] std::disable_sized_sentinel_for is missing specialisation for std::move_iterator
  2024-08-31 10:44 [Bug libstdc++/116549] New: std::disable_sized_sentinel_for is missing specialisation for std::move_iterator daidodo at gmail dot com
                   ` (7 preceding siblings ...)
  2024-09-03 15:18 ` cvs-commit at gcc dot gnu.org
@ 2024-09-04 20:35 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-09-04 20:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116549

--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:ee37d750262579a81799c5b56fe1ab936a840120

commit r14-10638-gee37d750262579a81799c5b56fe1ab936a840120
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Sep 2 11:29:13 2024 +0100

    libstdc++: Specialize std::disable_sized_sentinel_for for
std::move_iterator [PR116549]

    LWG 3736 added a partial specialization of this variable template for
    two std::move_iterator types. This is needed for the case where the
    types satisfy std::sentinel_for and are subtractable, but do not model
    the semantics requirements of std::sized_sentinel_for.

    libstdc++-v3/ChangeLog:

            PR libstdc++/116549
            * include/bits/stl_iterator.h (disable_sized_sentinel_for):
            Define specialization for two move_iterator types, as per LWG
            3736.
            * testsuite/24_iterators/move_iterator/lwg3736.cc: New test.

    (cherry picked from commit 819deae0a5bee079a7d5582fafaa098c26144ae8)

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-09-04 20:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-31 10:44 [Bug libstdc++/116549] New: std::disable_sized_sentinel_for is missing specialisation for std::move_iterator daidodo at gmail dot com
2024-08-31 11:07 ` [Bug libstdc++/116549] " daidodo at gmail dot com
2024-08-31 18:19 ` daniel.kruegler at googlemail dot com
2024-09-01  1:37 ` daidodo at gmail dot com
2024-09-02 10:07 ` redi at gcc dot gnu.org
2024-09-02 10:09 ` redi at gcc dot gnu.org
2024-09-02 10:22 ` redi at gcc dot gnu.org
2024-09-02 11:25 ` daidodo at gmail dot com
2024-09-03 15:18 ` cvs-commit at gcc dot gnu.org
2024-09-04 20:35 ` cvs-commit at gcc dot gnu.org

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).