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.133.124]) by sourceware.org (Postfix) with ESMTPS id C524C385C6EF for ; Tue, 12 Sep 2023 13:16:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C524C385C6EF 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=1694524612; 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=tNJNWxg+u3wIyXKlIyUpE7awKOvmEbbWYSpmIuXBs+E=; b=OBcan22dAksU4KUtVRUOZz6t7ihSVqzwN9FZE7wdVuSaJzoKL+YB0c3OCL8PNL1j9pEcwA ed1U/THcsX8FeXX/UTwctN+6/G9CLoj59c/SLOu/nBYhvtScP2ssSTvkBCocvUD7slYDRz 46O4LK/sm6Tcfot2Xbwj3pOfKCtzXbw= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-550-I7vXVJpLM7qJt2axpm6VmQ-1; Tue, 12 Sep 2023 09:16:51 -0400 X-MC-Unique: I7vXVJpLM7qJt2axpm6VmQ-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2bcba79cedcso62528861fa.1 for ; Tue, 12 Sep 2023 06:16:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694524609; x=1695129409; 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=tNJNWxg+u3wIyXKlIyUpE7awKOvmEbbWYSpmIuXBs+E=; b=s1i+Emky3N+HkcJMCbcGYfyqeFSZ13Zjb6QU7kZdg/qMtuKMA14U6sHO0vSRbmSQqa AdacgwKzyuvDnin+fQhGTwE8AIGS4klKYSPrSdE7pM4xBGUGnXmP/zO6GWdUFYXZquOv GUk/kOPHG0a4l8qJPHe4WgJ8rqGYa8OYTM/weop8LEY2GTSVNIo7kvRrYHo1lqN3cJxV GdpkLEGRTWCAiu7j5E3H2bhUEnACNS3/x2Vky9MxPi5nxewsQfuUEBKRPkQIo8qDIrgM P2OWArR1epKyM1Tp0ddSJButiSb/lSBsNR/hVw803Otf2Pyh4OENCM+yOBLZaDsL7ygG hgUg== X-Gm-Message-State: AOJu0YxUi4L8YJLHGtsLQp+s5W+J8i1AqvNWZhd1TEa4AmlKXjOolgvj JzmlLExCXu3KWVsayp9OsJzTIf3lp89IVo+FolGM1NLFnB5uFb0LD6XSkwNg3Esd4XzGzuAo2aS kQn4n1BlhxVQ1ZG/i8MRp14Mu0MZpYwM= X-Received: by 2002:a2e:b058:0:b0:2bc:b448:b8c0 with SMTP id d24-20020a2eb058000000b002bcb448b8c0mr10256863ljl.34.1694524609583; Tue, 12 Sep 2023 06:16:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRFOaylV0UefrY94c8vch5Ku789mi1Pues7/N4tJYUHRbQhCIdf+qI6g2ncoO2Z6KBFY1POAKclgwDEC/Oe/o= X-Received: by 2002:a2e:b058:0:b0:2bc:b448:b8c0 with SMTP id d24-20020a2eb058000000b002bcb448b8c0mr10256856ljl.34.1694524609414; Tue, 12 Sep 2023 06:16:49 -0700 (PDT) MIME-Version: 1.0 References: <20230912010852.1027184-1-ppalka@redhat.com> <20230912010852.1027184-3-ppalka@redhat.com> In-Reply-To: <20230912010852.1027184-3-ppalka@redhat.com> From: Jonathan Wakely Date: Tue, 12 Sep 2023 14:16:38 +0100 Message-ID: Subject: Re: [PATCH 3/3] libstdc++: Fix std::not_fn 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.2 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_H3,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:11, Patrick Palka via Libstdc++ wrote: > > The previous patch fixed perfect forwarding for std::bind_front. > This patch fixes the same issue for std::not_fn. > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk and > perhaps 13? Yes for both, thanks. > > PR libstdc++/111327 > > libstdc++-v3/ChangeLog: > > * include/std/functional (_GLIBCXX_NOT_FN_CALL_OP): Also define > a deleted fallback operator() overload. Constrain both the > main and deleted overloads accordingly. > * testsuite/20_util/function_objects/not_fn/111327.cc: New test. > --- > libstdc++-v3/include/std/functional | 10 +++++-- > .../20_util/function_objects/not_fn/111327.cc | 29 +++++++++++++++++++ > 2 files changed, 37 insertions(+), 2 deletions(-) > create mode 100644 libstdc++-v3/testsuite/20_util/function_objects/not_fn/111327.cc > > diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional > index c50b9e4d365..9551e38dfdb 100644 > --- a/libstdc++-v3/include/std/functional > +++ b/libstdc++-v3/include/std/functional > @@ -1061,7 +1061,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > // forwarding _M_fn and the function arguments with the same qualifiers, > // and deducing the return type and exception-specification. > #define _GLIBCXX_NOT_FN_CALL_OP( _QUALS ) \ > - template \ > + template + typename = enable_if_t<__is_invocable<_Fn _QUALS, _Args...>::value>> \ > _GLIBCXX20_CONSTEXPR \ > decltype(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>()) \ > operator()(_Args&&... __args) _QUALS \ > @@ -1070,7 +1071,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > { \ > return !std::__invoke(std::forward< _Fn _QUALS >(_M_fn), \ > std::forward<_Args>(__args)...); \ > - } > + } \ > + \ > + template + typename = enable_if_t::value>> \ > + void operator()(_Args&&... __args) _QUALS = delete; > + > _GLIBCXX_NOT_FN_CALL_OP( & ) > _GLIBCXX_NOT_FN_CALL_OP( const & ) > _GLIBCXX_NOT_FN_CALL_OP( && ) > diff --git a/libstdc++-v3/testsuite/20_util/function_objects/not_fn/111327.cc b/libstdc++-v3/testsuite/20_util/function_objects/not_fn/111327.cc > new file mode 100644 > index 00000000000..93e00ee8057 > --- /dev/null > +++ b/libstdc++-v3/testsuite/20_util/function_objects/not_fn/111327.cc > @@ -0,0 +1,29 @@ > +// PR libstdc++/111327 - std::bind_front (and std::not_fn) doesn't perfectly > +// forward according to value category of the call wrapper object > +// { dg-do compile { target c++17 } } > + > +#include > +#include > + > +struct F { > + void operator()(...) & = delete; > + bool operator()(...) const &; > +}; > + > +struct G { > + void operator()(...) && = delete; > + bool operator()(...) const &&; > +}; > + > +int main() { > + auto f = std::not_fn(F{}); > + f(); // { dg-error "deleted" } > + std::move(f)(); > + std::as_const(f)(); > + std::move(std::as_const(f))(); > + > + auto g = std::not_fn(G{}); > + g(); // { dg-error "deleted" } > + std::move(g)(); // { dg-error "deleted" } > + std::move(std::as_const(g))(); > +} > -- > 2.42.0.158.g94e83dcf5b >