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 B78BF3858C00 for ; Tue, 12 Sep 2023 01:09:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B78BF3858C00 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=1694480940; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hjMtkxM4eZRU2aacYPt/YDOFFIKjMe2qyL8ztKqGhic=; b=ePtO9GEg5C3rczxTEW1Cm3RgVkE+Foe7areu5eZHGkyWybKoW3YWCvVsiEkUeSSHxLr3LU roNHNMDz/Heb8sB5Fp4kgunpLblKx7Sypp0YshRsPaBnpEAI84qtg6U/ow7Kby2W/K7C6q xCMbeXxhyvhmUZZTm69EXMxIs/p6Ep8= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-81-yUJx32WAPPq53BkiTdMETQ-1; Mon, 11 Sep 2023 21:08:58 -0400 X-MC-Unique: yUJx32WAPPq53BkiTdMETQ-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6557c921df1so50529186d6.2 for ; Mon, 11 Sep 2023 18:08:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694480937; x=1695085737; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hjMtkxM4eZRU2aacYPt/YDOFFIKjMe2qyL8ztKqGhic=; b=fz8D+yL4KDcQa/aWy3kGNs8/HjHrKMbP2EE/a5kM66YnRMRT+8gWoJDJp8GwC9amwr iFEIUKfgX9sxa474LDBUytIwnCPkjbKDoo5VBDpP+7g9RQwsReC8brR7sfpvH0el7ROT iqF64oJRyqwPI9aGM7zk7M/jcPdd5lduZubr4jVU/kEoXWgDCPrcX9VZEm42yIdNY0Z+ C48u+26FcipaF78FH6M2Q4RDCPLa4bAik8s0YUuaTLuPXphW7PE5m4SFfWXZopHnSxvT +lrTnDmDqGRufEDl2nM5VEvTNcMTf8DHSHOlxpNGGQfwePZOGDJtTxBxxXEg36zuvEVF BSXA== X-Gm-Message-State: AOJu0Yw+9EZkqShnpoworEgBDvW9RpkiA7LDTb47VZYhsQDJOMVXOnR+ bsWplI5ITwBgAj0hvLrzSEshXlUWhXd9ZQHYLx+mnB9LxW5k/h8Bbwrsh9JzoG6TPsf/A9VWzFj vXQT4S8A13VZkw/c= X-Received: by 2002:ad4:580b:0:b0:649:cbd0:8124 with SMTP id dd11-20020ad4580b000000b00649cbd08124mr9857932qvb.36.1694480937576; Mon, 11 Sep 2023 18:08:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGFMl77EGCmej2coYm5RHtOhVOq/+RfzKTp2xHljH3sH+szgJfEAKXOwy8UpzapzSXVUq173A== X-Received: by 2002:ad4:580b:0:b0:649:cbd0:8124 with SMTP id dd11-20020ad4580b000000b00649cbd08124mr9857925qvb.36.1694480937247; Mon, 11 Sep 2023 18:08:57 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id qj10-20020a056214320a00b00655f35dcbcasm877643qvb.75.2023.09.11.18.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 18:08:56 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 3/3] libstdc++: Fix std::not_fn perfect forwarding [PR111327] Date: Mon, 11 Sep 2023 21:08:52 -0400 Message-ID: <20230912010852.1027184-3-ppalka@redhat.com> X-Mailer: git-send-email 2.42.0.158.g94e83dcf5b In-Reply-To: <20230912010852.1027184-1-ppalka@redhat.com> References: <20230912010852.1027184-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 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: 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? 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::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::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