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 35D833858C50 for ; Tue, 12 Sep 2023 01:08:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35D833858C50 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=1694480937; 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=9WRFQIOYZN9T22M3xWzJoB/cxaH6RGvb6dGeGk2yLR0=; b=PlPWuIwM2SHFYen3I3YAJYiuXaSid05U55YybOPKo6OshK1hMeJ2ynKYSpb/aPzybm68so uldynEobBzCCm1iGtIslm/qsaUytz4vU8Q86RgxiVSQymoiexZG++FsqIcnZeCajz9TAXj GQ1jdOFbOoy7cwDVlk8aXqhkWPujhhw= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-X31gnvdCOymT-8AG80BYdA-1; Mon, 11 Sep 2023 21:08:56 -0400 X-MC-Unique: X31gnvdCOymT-8AG80BYdA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-655d4cfcba5so31093236d6.0 for ; Mon, 11 Sep 2023 18:08:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694480936; x=1695085736; 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=9WRFQIOYZN9T22M3xWzJoB/cxaH6RGvb6dGeGk2yLR0=; b=CBaf3uTuNFr4p877oxgXTD0lgalT9gLhYf5MfiXQ9ltFEk5+NbCYDEGa5rRsMZD4lU uxobuwRHwYaNcUJvQZbWNa+HJHbSB+Uy3WQLPV+Pu4DLbZtU9boyrD9/nHOxl3jMj13l NPAItavSFB7TFfY8wmbXi9vAJLo0PbvwOHnd+hlc6coY2DYbtyH3Xz5O5gDue4FxepLm 9hXoRmp1yDb2T14/x9z64W3zWKqk+Hb5rm2gUqPGWc2MALbpufs3CRPGGmf+WoIFLkJf eFIyBJcLs5sR7eF3AiFpi9St1+hdnp4FFa+kymYoXZbh0gOJqmfTiI7Vu975TXEVgsES XwRQ== X-Gm-Message-State: AOJu0Yw9VqUdp+2MyjSMhZbeNkywQpQRu0J4MwfnUWVr+Tj+4gaDugCE IHvySIHKC1kXrT1GC3SnBWemk+Q2a4UEijIiXQFRt9kpP85HSzJp2ou9cP41fAbTR4hx8bVssR7 cAYS7RLL3me0Fe9g= X-Received: by 2002:a0c:fc02:0:b0:64c:f2e1:eb3 with SMTP id z2-20020a0cfc02000000b0064cf2e10eb3mr10093675qvo.45.1694480936277; Mon, 11 Sep 2023 18:08:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHQxM8ScpaDyVeeHx7JABtIXs1waVh22z9U/pklF7jjz5u8K6+bqU32LFutdUlhKpEZwQd4A== X-Received: by 2002:a0c:fc02:0:b0:64c:f2e1:eb3 with SMTP id z2-20020a0cfc02000000b0064cf2e10eb3mr10093666qvo.45.1694480935974; Mon, 11 Sep 2023 18:08:55 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 18:08:55 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 2/3] libstdc++: Fix std::bind_front perfect forwarding [PR111327] Date: Mon, 11 Sep 2023 21:08:51 -0400 Message-ID: <20230912010852.1027184-2-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: 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. 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