From patchwork Tue Sep 27 11:00:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp264609wrt; Tue, 27 Sep 2022 04:01:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7FGFOwDhyduAss6qIkarVjFKfCGPQBERDMtuOUR2/lTh79Or911CagHGEVoQ31cLKeGGIV X-Received: by 2002:a17:907:a4a:b0:77b:c1b2:479a with SMTP id be10-20020a1709070a4a00b0077bc1b2479amr22825102ejc.109.1664276490890; Tue, 27 Sep 2022 04:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664276490; cv=none; d=google.com; s=arc-20160816; b=C3KPI0N4TDEPSBXoG/L7YgxbflEdCptqvCvVJIBJPM9oWkWX3AqwjcLY6RPJVtXo/q Y/18v624ivGRyCAmu2T1siR30vyRQDcRpWre4rjW0oCO0qp5IFAfQbiAqYDkiG6u0F1W pyrjjK/32p4h9pI4wlzigylW7BkSMQpmZqYbcMEVe3Utbsqx/LVDnCBbGo39+PzbXRGo bfSoSjiJkyhmEm/uE9Sac1a6vtcX0PvjFbHboQ4Wlk5fMnbkNHZVLMadtEPssOVBlmT3 7JaHYhw+6K581f6yONjZBtiNFnMXOsV1ZK6XRC60Dm9dAF2v6+kYuxq+Dmq61jTUEpcX y5xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=2VeFMzKgRp7cKnnWQVm4BIOEA2DmeRNu0+iuoq9ujgA=; b=ycQxrshBVDe/WFvtfIAS1i+S4uJqoo9Y/bjh04+qSYw3Fu1hbQt5QHzF5c32iNWM00 qsWt4IRWfIrXwtRByIYPc8wvc1eDmVY/+ZaGVtjCR0ArYV9k0wXRXJr7dPOSjayoGh0G M+faMLDjlnS9THtvJ6zJsUIIqCtCv6OUHzoEOEpvNltw0nzvse4OEelD9zn40S7HuB2W qF9mjXIh3tn5OQSscWHqISblc6pzp+b7PjjD2MydGauC4V1vwDR7UTTjFjCCRfGOIKvX wZY6a9FNOtrA7qv8nh/EWuH9K8qBLhzHFt+qWkW78eU5dytpTqvtLvI73e45yhyDBDqL D68w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wX01Fvrb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gb20-20020a170907961400b007800b181a0csi1261060ejc.300.2022.09.27.04.01.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 04:01:30 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wX01Fvrb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7D1FC385AC2D for ; Tue, 27 Sep 2022 11:01:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D1FC385AC2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664276460; bh=2VeFMzKgRp7cKnnWQVm4BIOEA2DmeRNu0+iuoq9ujgA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wX01FvrbzoUt4J75wVLoQMqrtZZu9zV+ltsj7x5DGC9HznlGujfWxUOqk4/AkOnay xeyhNHUEj7o9TD5QFbMi+24tJywmSs85+DjwXzjIGL+QPj7ffTCW11gXnlPXfAjes9 xBhz1rIqJ0r2CSySc+jkCu8LFsqu7hpFvkTFD4T0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 391DF3858009 for ; Tue, 27 Sep 2022 11:00:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 391DF3858009 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-385-gxs0Mgz8Ob-Cdg6avmYNtw-1; Tue, 27 Sep 2022 07:00:14 -0400 X-MC-Unique: gxs0Mgz8Ob-Cdg6avmYNtw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B13786EB32; Tue, 27 Sep 2022 11:00:14 +0000 (UTC) Received: from localhost (unknown [10.33.36.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02F512166B26; Tue, 27 Sep 2022 11:00:13 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Adjust deduction guides for static operator() [PR106651] Date: Tue, 27 Sep 2022 12:00:13 +0100 Message-Id: <20220927110013.2378598-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745120385710453372?= X-GMAIL-MSGID: =?utf-8?q?1745120385710453372?= Tested x86_64-linux. Pushed to trunk. -- >8 -- Adjust the deduction guides for std::function and std::packaged_task to work with static call operators. This finishes the implementation of P1169R4 for C++23. libstdc++-v3/ChangeLog: PR c++/106651 * include/bits/std_function.h (__function_guide_t): New alias template. [__cpp_static_call_operator] (__function_guide_static_helper): New class template. (function): Use __function_guide_t in deduction guide. * include/std/future (packaged_task): Use __function_guide_t in deduction guide. * testsuite/20_util/function/cons/deduction_c++23.cc: New test. * testsuite/30_threads/packaged_task/cons/deduction_c++23.cc: New test. --- libstdc++-v3/include/bits/std_function.h | 25 ++++++++++++++++--- libstdc++-v3/include/std/future | 4 +-- .../20_util/function/cons/deduction_c++23.cc | 23 +++++++++++++++++ .../packaged_task/cons/deduction_c++23.cc | 23 +++++++++++++++++ 4 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/function/cons/deduction_c++23.cc create mode 100644 libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction_c++23.cc diff --git a/libstdc++-v3/include/bits/std_function.h b/libstdc++-v3/include/bits/std_function.h index 96918a04a35..f5423a3a5c7 100644 --- a/libstdc++-v3/include/bits/std_function.h +++ b/libstdc++-v3/include/bits/std_function.h @@ -697,12 +697,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > { using type = _Res(_Args...); }; +#if __cpp_static_call_operator >= 202207L && __cpp_concepts >= 202002L + template + struct __function_guide_static_helper + { }; + + template + struct __function_guide_static_helper<_Res (*) (_Args...) noexcept(_Nx)> + { using type = _Res(_Args...); }; + + template + using __function_guide_t = typename __conditional_t< + requires (_Fn& __f) { (void) __f.operator(); }, + __function_guide_static_helper<_Op>, + __function_guide_helper<_Op>>::type; +#else + template + using __function_guide_t = typename __function_guide_helper<_Op>::type; +#endif + template function(_Res(*)(_ArgTypes...)) -> function<_Res(_ArgTypes...)>; - template::type> - function(_Functor) -> function<_Signature>; + template> + function(_Fn) -> function<_Signature>; #endif // [20.7.15.2.6] null pointer comparisons diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index a1b2d7f1d3a..cf08c155a24 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -1649,8 +1649,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template packaged_task(_Res(*)(_ArgTypes...)) -> packaged_task<_Res(_ArgTypes...)>; - template::type> + template> packaged_task(_Fun) -> packaged_task<_Signature>; #endif diff --git a/libstdc++-v3/testsuite/20_util/function/cons/deduction_c++23.cc b/libstdc++-v3/testsuite/20_util/function/cons/deduction_c++23.cc new file mode 100644 index 00000000000..17454ea4108 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function/cons/deduction_c++23.cc @@ -0,0 +1,23 @@ +// { dg-options "-std=gnu++23" } +// { dg-do compile { target c++23 } } + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test_static_call_operator() +{ + struct F1 { static long operator()() { return 0; } }; + std::function func1 = F1{}; + check_type>(func1); + + struct F2 { static float operator()(char, void*) noexcept { return 0; } }; + std::function func2 = F2{}; + check_type>(func2); +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction_c++23.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction_c++23.cc new file mode 100644 index 00000000000..e36edfa0359 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction_c++23.cc @@ -0,0 +1,23 @@ +// { dg-options "-std=gnu++23" } +// { dg-do compile { target c++23 } } + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void +test_static_call_operator() +{ + struct F1 { static long operator()() { return 0; } }; + std::packaged_task task1{ F1{} }; + check_type>(task1); + + struct F2 { static float operator()(char, void*) noexcept { return 0; } }; + std::packaged_task task2{ F2{} }; + check_type>(task2); +}