From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B23A73830B58 for ; Tue, 12 Sep 2023 13:16:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B23A73830B58 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694524581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vjXaBV9ewFLlid3mpAYK11h9s3xn1wnMZXFTWZ3JFM4=; b=bp3mN5jngviTFGbX6PGOeDe5MEolEdhKF5ePzKJQ4DDhpkYFSDHuLZD5+ah0VMeeNcu3no S0jVmuCuvVWw89YaRGb79R/2V2raGVtAiZzMGBOQ7VZA0aWLdA45SUOU3ieExmwQFOt1YQ ArGrunXyn7Jaa7fER4/KQnqtV05Eey8= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-573-ZZZSepxoOBu0BjoHHxqsrw-1; Tue, 12 Sep 2023 09:16:20 -0400 X-MC-Unique: ZZZSepxoOBu0BjoHHxqsrw-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-5007cabf295so3604063e87.0 for ; Tue, 12 Sep 2023 06:16:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694524578; x=1695129378; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vjXaBV9ewFLlid3mpAYK11h9s3xn1wnMZXFTWZ3JFM4=; b=eVV7KkpwPcjBEQmC1v+0SMh0XI5mltUJyIMNYf+vDn3dOLuhLzcgjK9A/NjhCw2B4A 0vrfddfvHjsWMp42tElLaJYYnZccB4njWz0IIgIm8RrsXIWURK2QPr8GCcGiOedqhA/c tnjMA75IDugsgKMoG5okte0FBfFqGyOFotnPQjBKD/5nnEhG2o+7R6lgmeHKSWeU0a7Q Y0S2zBFPS0+h68XnMKd8TY9h2/d9zfxJF8R5s9/zMcz7P6XYGw0bacz2agDT+OjpxhL1 TznBwAjoQ0k895ZJ3CNt1d1POxsoMIQOq+jThSxGtNmytAMbc9wMKWvtdkZbGR3VQ4Xf +L7w== X-Gm-Message-State: AOJu0Yyr/fvP1X09qdeIMrnRlvIoerc3zkKw15UTq8xpr14aaf0OyC66 Jr1E3FIu4ZnCa11uaJqp/D4fROnbJ5Scam/ZLsN9GPq8EG6x6glHvu0b+M4XvnVPqjS96z7ZlUr DmqE45SoYxc+4ffppF6fiPBWvo+cYR+Wx5pvrJPo= X-Received: by 2002:a05:6512:a93:b0:4fd:d254:edc6 with SMTP id m19-20020a0565120a9300b004fdd254edc6mr887751lfu.26.1694524578574; Tue, 12 Sep 2023 06:16:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOXEN/Qm1vcjB/pleVh6rp/8QsfCBmRE73sq8ZgvGKJZfXTkogtnIVIt8a6YPmR1NWDtfknAK+jOXCULaWYoU= X-Received: by 2002:a05:6512:a93:b0:4fd:d254:edc6 with SMTP id m19-20020a0565120a9300b004fdd254edc6mr887744lfu.26.1694524578225; Tue, 12 Sep 2023 06:16:18 -0700 (PDT) MIME-Version: 1.0 References: <20230912010852.1027184-1-ppalka@redhat.com> <20230912010852.1027184-2-ppalka@redhat.com> In-Reply-To: <20230912010852.1027184-2-ppalka@redhat.com> From: Jonathan Wakely Date: Tue, 12 Sep 2023 14:16:07 +0100 Message-ID: Subject: Re: [PATCH 2/3] libstdc++: Fix std::bind_front perfect forwarding [PR111327] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,URI_HEX autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, 12 Sept 2023 at 02:09, Patrick Palka via Libstdc++ wrote: > > In order to properly implement a perfect forwarding call wrapper > (before 'deducing this' at least) we need a total of 8 operator() > overloads, 4 main ones and 4 deleted ones for each const/ref qual pair, > as described in section 5.5 of P0847R6. Otherwise the wrapper may > not perfectly forward according to the value category and constness > of the wrapped object. This patch fixes this bug in std::bind_front. OK for trunk, thanks. > > PR libstdc++/111327 > > libstdc++-v3/ChangeLog: > > * include/std/functional (_Bind_front::operator()): Add deleted > fallback overloads for each const/ref qualifier pair. Give the > main overloads dummy constraints to make them more specialized > than the deleted overloads. > * testsuite/20_util/function_objects/bind_front/111327.cc: New test. > --- > libstdc++-v3/include/std/functional | 16 ++++++++ > .../function_objects/bind_front/111327.cc | 41 +++++++++++++++++++ > 2 files changed, 57 insertions(+) > create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/bind_front/111327.cc > > diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional > index 7d1b890bb4e..c50b9e4d365 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 00000000000..6eb51994476 > --- /dev/null > +++ b/libstdc++-v3/testsuite/20_util/function_objects/bind_front/111327.cc > @@ -0,0 +1,41 @@ > +// PR libstdc++/111327 - std::bind_front doesn't 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))(); > +} > -- > 2.42.0.158.g94e83dcf5b >