From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6339E3846034; Sat, 24 Apr 2021 18:33:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6339E3846034 From: "hewillk at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/100249] New: missing forwarding std::__invoke result in ranges::is_permutation and ranges::clamp Date: Sat, 24 Apr 2021 18:33:28 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hewillk at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Apr 2021 18:33:28 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100249 Bug ID: 100249 Summary: missing forwarding std::__invoke result in ranges::is_permutation and ranges::clamp 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::is_permutation in ranges_algo.h#L808: auto __proj_scan =3D std::__invoke(__proj1, *__scan); auto __comp_scan =3D [&] (_Tp&& __arg) { return std::__invoke(__pred, __proj_scan, std::forward<_Tp>(__arg)); }; the __proj_scan seems to forget to use auto&& to receive the std::__ invoke call, which will cause compile failure if the return type is non-copyable: https://godbolt.org/z/WaKc7bWM4 also, we should perfect forward the type of __proj_scan to the next std::__invoke call, and ranges::clamp in ranges_algo.h#L3232 has the same issue: auto&& __proj_val =3D std::__invoke(__proj, __val); if (std::__invoke(__comp, __proj_val, std::__invoke(__proj, __lo))) return __lo; when the type of __proj_val is an rvalue reference, we need to convert it to rvalue for the next std::__invoke call: https://godbolt.org/z/1G7aqxs3c. So I think it should be relatively safe to inline all std::__invoke calls.=