From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 0DD333830B70; Tue, 12 Sep 2023 15:28:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DD333830B70 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694532484; bh=FYLXh/+1cgZY0FPsGY3BPWQsVyxnqoSBkCzZKXNBekE=; h=From:To:Subject:Date:From; b=qOZaPmP1MrGaLaNv6ShXmxKiBWSo2OUsac11PoFW5WGkV/wiaKWtBC2g9HekWgCuY EtHeJaE5EQnVHubvI1aJwAzFJwYz3OP2NaOaBTq9XZMePXP6ghohyAopxyvjLQMFRe EAZ1QxF7+N5xgi1hGxNERYbC4cjlcvfoYqnN/xKo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-3902] libstdc++: Fix std::bind_front perfect forwarding [PR111327] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: f1e87aee5b7023fb4f5791c6869db705e18c2705 X-Git-Newrev: 4289f6ceefe74ea46e792692448c06197ac20c86 Message-Id: <20230912152804.0DD333830B70@sourceware.org> Date: Tue, 12 Sep 2023 15:28:03 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4289f6ceefe74ea46e792692448c06197ac20c86 commit r14-3902-g4289f6ceefe74ea46e792692448c06197ac20c86 Author: Patrick Palka Date: Tue Sep 12 11:23:12 2023 -0400 libstdc++: Fix std::bind_front perfect forwarding [PR111327] In order to properly implement a perfect forwarding call wrapper (without C++23 deducing 'this') we need a total of 8 operator() overloads, 4 enabled ones and 4 deleted ones, i.e. two for each const/ref qual pair, as described in section 5.5 of P0847R6. Otherwise the wrapper may not do the right thing if the underlying function object has a deleted const/ref-qualified operator() overload. This patch fixes this issue in std::bind_front. PR libstdc++/111327 libstdc++-v3/ChangeLog: * include/std/functional (_Bind_front::operator()): Add deleted fallback overloads for each const/ref qualifier pair. Give the enabled overloads dummy constraints to make each one more specialized than the corresponding deleted overload. * testsuite/20_util/function_objects/bind_front/111327.cc: New test. Diff: --- libstdc++-v3/include/std/functional | 16 +++++++++ .../20_util/function_objects/bind_front/111327.cc | 41 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 7d1b890bb4e9..c50b9e4d3658 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -938,6 +938,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~_Bind_front() = default; template + requires true constexpr invoke_result_t<_Fd&, _BoundArgs&..., _CallArgs...> operator()(_CallArgs&&... __call_args) & @@ -948,6 +949,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + requires true constexpr invoke_result_t operator()(_CallArgs&&... __call_args) const & @@ -959,6 +961,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + requires true constexpr invoke_result_t<_Fd, _BoundArgs..., _CallArgs...> operator()(_CallArgs&&... __call_args) && @@ -969,6 +972,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + requires true constexpr invoke_result_t operator()(_CallArgs&&... __call_args) const && @@ -979,6 +983,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION std::forward<_CallArgs>(__call_args)...); } + template + void operator()(_CallArgs&&...) & = delete; + + template + void operator()(_CallArgs&&...) const & = delete; + + template + void operator()(_CallArgs&&...) && = delete; + + template + void operator()(_CallArgs&&...) const && = delete; + private: using _BoundIndices = index_sequence_for<_BoundArgs...>; diff --git a/libstdc++-v3/testsuite/20_util/function_objects/bind_front/111327.cc b/libstdc++-v3/testsuite/20_util/function_objects/bind_front/111327.cc new file mode 100644 index 000000000000..fcfb9f9c7c02 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/bind_front/111327.cc @@ -0,0 +1,41 @@ +// PR libstdc++/111327 - std::bind_front (and std::not_fn) doesn't always +// perfectly forward according to value category of the call wrapper object +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } + +#include +#include + +struct F { + void operator()(...) & = delete; + void operator()(...) const &; +}; + +struct G { + void operator()(...) && = delete; + void operator()(...) const &&; +}; + +int main() { + auto f0 = std::bind_front(F{}); + f0(); // { dg-error "deleted" } + std::move(f0)(); + std::as_const(f0)(); + std::move(std::as_const(f0))(); + + auto g0 = std::bind_front(G{}); + g0(); // { dg-error "deleted" } + std::move(g0)(); // { dg-error "deleted" } + std::move(std::as_const(g0))(); + + auto f1 = std::bind_front(F{}, 42); + f1(); // { dg-error "deleted" } + std::move(f1)(); + std::as_const(f1)(); + std::move(std::as_const(f1))(); + + auto g1 = std::bind_front(G{}, 42); + g1(); // { dg-error "deleted" } + std::move(g1)(); // { dg-error "deleted" } + std::move(std::as_const(g1))(); +}