public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100187] New: ranges::search_n helper lambda misses forwarding return type
@ 2021-04-21 16:09 hewillk at gmail dot com
  2021-04-21 16:19 ` [Bug libstdc++/100187] " hewillk at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: hewillk at gmail dot com @ 2021-04-21 16:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100187
           Summary: ranges::search_n helper lambda misses forwarding
                    return type
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

ranges_algo.h#L565:

auto __value_comp = [&] <typename _Rp> (_Rp&& __arg) {
  return std::__invoke(__pred, std::forward<_Rp>(__arg), __value);
};

__value_comp misses forwarding the return type (-> decltype(auto)) which made
the following unnecessary failed:

#include <algorithm>

struct Bool {
  operator bool() { return true; };
  Bool() = default;
  Bool(const Bool&) = delete;
};

int main() {
  Bool b;
  std::vector v{1, 0};
  std::ranges::search_n(v, 1, 1, [&](auto, auto) -> Bool& { return b; });
}

https://godbolt.org/z/zjn8Gz3c5

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

* [Bug libstdc++/100187] ranges::search_n helper lambda misses forwarding return type
  2021-04-21 16:09 [Bug libstdc++/100187] New: ranges::search_n helper lambda misses forwarding return type hewillk at gmail dot com
@ 2021-04-21 16:19 ` hewillk at gmail dot com
  2021-04-21 16:44 ` hewillk at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: hewillk at gmail dot com @ 2021-04-21 16:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from 康桓瑋 <hewillk at gmail dot com> ---
Same with is_permutation helper lambda __comp_scan in ranges_algo.h#L807:

auto __comp_scan = [&] <typename _Tp> (_Tp&& __arg) {
  return std::__invoke(__pred, __proj_scan,
      std::forward<_Tp>(__arg));
};

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

* [Bug libstdc++/100187] ranges::search_n helper lambda misses forwarding return type
  2021-04-21 16:09 [Bug libstdc++/100187] New: ranges::search_n helper lambda misses forwarding return type hewillk at gmail dot com
  2021-04-21 16:19 ` [Bug libstdc++/100187] " hewillk at gmail dot com
@ 2021-04-21 16:44 ` hewillk at gmail dot com
  2021-04-22  6:06 ` hewillk at gmail dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: hewillk at gmail dot com @ 2021-04-21 16:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from 康桓瑋 <hewillk at gmail dot com> ---
Or more consistent, just -> bool.

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

* [Bug libstdc++/100187] ranges::search_n helper lambda misses forwarding return type
  2021-04-21 16:09 [Bug libstdc++/100187] New: ranges::search_n helper lambda misses forwarding return type hewillk at gmail dot com
  2021-04-21 16:19 ` [Bug libstdc++/100187] " hewillk at gmail dot com
  2021-04-21 16:44 ` hewillk at gmail dot com
@ 2021-04-22  6:06 ` hewillk at gmail dot com
  2021-04-22 19:12 ` [Bug libstdc++/100187] Helper lambda in ranges_algo.h " ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: hewillk at gmail dot com @ 2021-04-22  6:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from 康桓瑋 <hewillk at gmail dot com> ---
Hey, the __remove_fn helper lambda __pred in ranges_algo.h#L1259 also has this
issue, we need to forward the return type of the operator==.

You can see https://godbolt.org/z/ro34WYGnW for the failure case, thanks.

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

* [Bug libstdc++/100187] Helper lambda in ranges_algo.h misses forwarding return type
  2021-04-21 16:09 [Bug libstdc++/100187] New: ranges::search_n helper lambda misses forwarding return type hewillk at gmail dot com
                   ` (2 preceding siblings ...)
  2021-04-22  6:06 ` hewillk at gmail dot com
@ 2021-04-22 19:12 ` ppalka at gcc dot gnu.org
  2021-04-28  3:23 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-22 19:12 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
                 CC|                            |ppalka at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-04-22

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed.

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

* [Bug libstdc++/100187] Helper lambda in ranges_algo.h misses forwarding return type
  2021-04-21 16:09 [Bug libstdc++/100187] New: ranges::search_n helper lambda misses forwarding return type hewillk at gmail dot com
                   ` (3 preceding siblings ...)
  2021-04-22 19:12 ` [Bug libstdc++/100187] Helper lambda in ranges_algo.h " ppalka at gcc dot gnu.org
@ 2021-04-28  3:23 ` cvs-commit at gcc dot gnu.org
  2021-10-13 13:51 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-28  3:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

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

commit r12-178-gd91e7eab3a2c3957c2220ad71e62d9fc78cccb9b
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Apr 27 23:21:19 2021 -0400

    libstdc++: Fix various bugs in ranges_algo.h [PR100187, ...]

    This fixes some bugs with our ranges algorithms in uncommon situations,
    such as when the return type of a predicate is a non-copyable class type
    that's implicitly convertible to bool (PR100187), when a comparison
    predicate isn't invocable as an rvalue (PR100237), and when the return
    type of a projection function is non-copyable (PR100249).

    This also fixes PR100287, which reports that we're moving __first twice
    when constructing with it an empty subrange in ranges::partition.

    libstdc++-v3/ChangeLog:

            PR libstdc++/100187
            PR libstdc++/100237
            PR libstdc++/100249
            PR libstdc++/100287
            * include/bits/ranges_algo.h (__search_n_fn::operator()): Give
            the __value_comp lambda an explicit bool return type.
            (__is_permutation_fn::operator()): Give the __proj_scan local
            variable auto&& return type.  Give the __comp_scan lambda an
            explicit bool return type.
            (__remove_fn::operator()): Give the __pred lambda an explicit
            bool return type.
            (__partition_fn::operator()): Don't std::move __first twice
            when returning an empty subrange.
            (__min_fn::operator()): Don't std::move __comp.
            (__max_fn::operator()): Likewise.
            (__minmax_fn::operator()): Likewise.

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

* [Bug libstdc++/100187] Helper lambda in ranges_algo.h misses forwarding return type
  2021-04-21 16:09 [Bug libstdc++/100187] New: ranges::search_n helper lambda misses forwarding return type hewillk at gmail dot com
                   ` (4 preceding siblings ...)
  2021-04-28  3:23 ` cvs-commit at gcc dot gnu.org
@ 2021-10-13 13:51 ` cvs-commit at gcc dot gnu.org
  2021-10-13 13:56 ` cvs-commit at gcc dot gnu.org
  2021-10-13 13:58 ` ppalka at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-13 13:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

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

commit r11-9145-gcb261f0e8fc08fb49f74002582ad5713cda684f7
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Apr 27 23:21:19 2021 -0400

    libstdc++: Fix various bugs in ranges_algo.h [PR100187, ...]

    This fixes some bugs with our ranges algorithms in uncommon situations,
    such as when the return type of a predicate is a non-copyable class type
    that's implicitly convertible to bool (PR100187), when a comparison
    predicate isn't invocable as an rvalue (PR100237), and when the return
    type of a projection function is non-copyable (PR100249).

    This also fixes PR100287, which reports that we're moving __first twice
    when constructing with it an empty subrange in ranges::partition.

    libstdc++-v3/ChangeLog:

            PR libstdc++/100187
            PR libstdc++/100237
            PR libstdc++/100249
            PR libstdc++/100287
            * include/bits/ranges_algo.h (__search_n_fn::operator()): Give
            the __value_comp lambda an explicit bool return type.
            (__is_permutation_fn::operator()): Give the __proj_scan local
            variable auto&& return type.  Give the __comp_scan lambda an
            explicit bool return type.
            (__remove_fn::operator()): Give the __pred lambda an explicit
            bool return type.
            (__partition_fn::operator()): Don't std::move __first twice
            when returning an empty subrange.
            (__min_fn::operator()): Don't std::move __comp.
            (__max_fn::operator()): Likewise.
            (__minmax_fn::operator()): Likewise.

    (cherry picked from commit d91e7eab3a2c3957c2220ad71e62d9fc78cccb9b)

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

* [Bug libstdc++/100187] Helper lambda in ranges_algo.h misses forwarding return type
  2021-04-21 16:09 [Bug libstdc++/100187] New: ranges::search_n helper lambda misses forwarding return type hewillk at gmail dot com
                   ` (5 preceding siblings ...)
  2021-10-13 13:51 ` cvs-commit at gcc dot gnu.org
@ 2021-10-13 13:56 ` cvs-commit at gcc dot gnu.org
  2021-10-13 13:58 ` ppalka at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-13 13:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:139bafaaba0c775ca65712621bd60e079b488d73

commit r10-10210-g139bafaaba0c775ca65712621bd60e079b488d73
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Apr 27 23:21:19 2021 -0400

    libstdc++: Fix various bugs in ranges_algo.h [PR100187, ...]

    This fixes some bugs with our ranges algorithms in uncommon situations,
    such as when the return type of a predicate is a non-copyable class type
    that's implicitly convertible to bool (PR100187), when a comparison
    predicate isn't invocable as an rvalue (PR100237), and when the return
    type of a projection function is non-copyable (PR100249).

    This also fixes PR100287, which reports that we're moving __first twice
    when constructing with it an empty subrange in ranges::partition.

    libstdc++-v3/ChangeLog:

            PR libstdc++/100187
            PR libstdc++/100237
            PR libstdc++/100249
            PR libstdc++/100287
            * include/bits/ranges_algo.h (__search_n_fn::operator()): Give
            the __value_comp lambda an explicit bool return type.
            (__is_permutation_fn::operator()): Give the __proj_scan local
            variable auto&& return type.  Give the __comp_scan lambda an
            explicit bool return type.
            (__remove_fn::operator()): Give the __pred lambda an explicit
            bool return type.
            (__partition_fn::operator()): Don't std::move __first twice
            when returning an empty subrange.
            (__min_fn::operator()): Don't std::move __comp.
            (__max_fn::operator()): Likewise.
            (__minmax_fn::operator()): Likewise.

    (cherry picked from commit d91e7eab3a2c3957c2220ad71e62d9fc78cccb9b)

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

* [Bug libstdc++/100187] Helper lambda in ranges_algo.h misses forwarding return type
  2021-04-21 16:09 [Bug libstdc++/100187] New: ranges::search_n helper lambda misses forwarding return type hewillk at gmail dot com
                   ` (6 preceding siblings ...)
  2021-10-13 13:56 ` cvs-commit at gcc dot gnu.org
@ 2021-10-13 13:58 ` ppalka at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-10-13 13:58 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |10.4

--- Comment #8 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for 10.4/11.3/12

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

end of thread, other threads:[~2021-10-13 13:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 16:09 [Bug libstdc++/100187] New: ranges::search_n helper lambda misses forwarding return type hewillk at gmail dot com
2021-04-21 16:19 ` [Bug libstdc++/100187] " hewillk at gmail dot com
2021-04-21 16:44 ` hewillk at gmail dot com
2021-04-22  6:06 ` hewillk at gmail dot com
2021-04-22 19:12 ` [Bug libstdc++/100187] Helper lambda in ranges_algo.h " ppalka at gcc dot gnu.org
2021-04-28  3:23 ` cvs-commit at gcc dot gnu.org
2021-10-13 13:51 ` cvs-commit at gcc dot gnu.org
2021-10-13 13:56 ` cvs-commit at gcc dot gnu.org
2021-10-13 13:58 ` ppalka 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).