public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100237] New: Unnecessary std::move in ranges::min, ranges::max and ranges::minmax
@ 2021-04-23 17:28 hewillk at gmail dot com
  2021-04-23 19:09 ` [Bug libstdc++/100237] " ppalka at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: hewillk at gmail dot com @ 2021-04-23 17:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100237
           Summary: Unnecessary std::move in ranges::min, ranges::max and
                    ranges::minmax
           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: ---

Hey, in ranges_algo.h#L3121:

constexpr const _Tp&
operator()(const _Tp& __a, const _Tp& __b,
           _Comp __comp = {}, _Proj __proj = {}) const
{
  if (std::__invoke(std::move(__comp),
                    std::__invoke(__proj, __b),
                    std::__invoke(__proj, __a)))
    return __b;
  else
    return __a;
}

Although it is unclear why there is a std::move in ranges::min, ranges::max,
and ranges::minmax, it is obviously unnecessary and will lead to the following
valid code failed:

#include <algorithm>

struct Comp {
  constexpr bool operator()(int, int) & { return true; };
} comp;

static_assert(        std::min(0, 1, comp));
static_assert(std::ranges::min(0, 1, comp));

static_assert(        std::max(0, 1, comp));
static_assert(std::ranges::max(0, 1, comp));

static_assert(        std::minmax(0, 1, comp).first);
static_assert(std::ranges::minmax(0, 1, comp).min);

https://godbolt.org/z/MbG8zbcGY

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

* [Bug libstdc++/100237] Unnecessary std::move in ranges::min, ranges::max and ranges::minmax
  2021-04-23 17:28 [Bug libstdc++/100237] New: Unnecessary std::move in ranges::min, ranges::max and ranges::minmax hewillk at gmail dot com
@ 2021-04-23 19:09 ` ppalka at gcc dot gnu.org
  2021-04-28  3:23 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-23 19:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Good point, confirmed.  It seems clear from the definition of the
indirect_strict_weak_order concept that these algorithms are expected to invoke
the predicate as an lvalue, so it's wrong to std::move it.

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

* [Bug libstdc++/100237] Unnecessary std::move in ranges::min, ranges::max and ranges::minmax
  2021-04-23 17:28 [Bug libstdc++/100237] New: Unnecessary std::move in ranges::min, ranges::max and ranges::minmax hewillk at gmail dot com
  2021-04-23 19:09 ` [Bug libstdc++/100237] " 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)
  4 siblings, 0 replies; 6+ 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=100237

--- Comment #2 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] 6+ messages in thread

* [Bug libstdc++/100237] Unnecessary std::move in ranges::min, ranges::max and ranges::minmax
  2021-04-23 17:28 [Bug libstdc++/100237] New: Unnecessary std::move in ranges::min, ranges::max and ranges::minmax hewillk at gmail dot com
  2021-04-23 19:09 ` [Bug libstdc++/100237] " 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
  4 siblings, 0 replies; 6+ 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=100237

--- Comment #3 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] 6+ messages in thread

* [Bug libstdc++/100237] Unnecessary std::move in ranges::min, ranges::max and ranges::minmax
  2021-04-23 17:28 [Bug libstdc++/100237] New: Unnecessary std::move in ranges::min, ranges::max and ranges::minmax hewillk at gmail dot com
                   ` (2 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
  4 siblings, 0 replies; 6+ 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=100237

--- Comment #4 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] 6+ messages in thread

* [Bug libstdc++/100237] Unnecessary std::move in ranges::min, ranges::max and ranges::minmax
  2021-04-23 17:28 [Bug libstdc++/100237] New: Unnecessary std::move in ranges::min, ranges::max and ranges::minmax hewillk at gmail dot com
                   ` (3 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
  4 siblings, 0 replies; 6+ 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=100237

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

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

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

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23 17:28 [Bug libstdc++/100237] New: Unnecessary std::move in ranges::min, ranges::max and ranges::minmax hewillk at gmail dot com
2021-04-23 19:09 ` [Bug libstdc++/100237] " 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).