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 2C29A3857811 for ; Mon, 25 Apr 2022 16:06:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2C29A3857811 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-376-dbBZ-A4EO9mOHJMC_9bRxw-1; Mon, 25 Apr 2022 12:06:10 -0400 X-MC-Unique: dbBZ-A4EO9mOHJMC_9bRxw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 64F1383397F; Mon, 25 Apr 2022 16:06:10 +0000 (UTC) Received: from localhost (unknown [10.33.36.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DB0DC2812B; Mon, 25 Apr 2022 16:06:09 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add deduction guides for std::packaged_task [PR105375] Date: Mon, 25 Apr 2022 17:06:09 +0100 Message-Id: <20220425160609.1957724-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit 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, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Apr 2022 16:06:13 -0000 Tested powerpc64le-linux, pushed to trunk. -- >8 -- This change was LWG 3117. The test is copied from 20_util/function/cons/deduction.cc libstdc++-v3/ChangeLog: PR libstdc++/105375 * include/std/future (packaged_task): Add deduction guides. * testsuite/30_threads/packaged_task/cons/deduction.cc: New test. --- libstdc++-v3/include/std/future | 11 +++ .../packaged_task/cons/deduction.cc | 85 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction.cc diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index cba40dc0883..a9268cade91 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -1622,6 +1622,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } }; + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3117. Missing packaged_task deduction guides +#if __cpp_deduction_guides >= 201606 + template + packaged_task(_Res(*)(_ArgTypes...)) -> packaged_task<_Res(_ArgTypes...)>; + + template::type> + packaged_task(_Fun) -> packaged_task<_Signature>; +#endif + /// swap template inline void diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction.cc new file mode 100644 index 00000000000..0eb69763ab9 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction.cc @@ -0,0 +1,85 @@ +// // Copyright (C) 2017-2022 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do compile { target c++17 } } + +#include + +template struct require_same; +template struct require_same { using type = void; }; + +template + typename require_same::type + check_type(U&) { } + +void f0v(); +void f0vn() noexcept; +int f0i(); +int f0in() noexcept; +long f1l(int&); +long f1ln(double*) noexcept; + +void +test01() +{ + std::packaged_task task1{f0v}; + check_type>(task1); + + std::packaged_task task2{f0vn}; + check_type>(task2); + + std::packaged_task task3{f0i}; + check_type>(task3); + + std::packaged_task task4{f0in}; + check_type>(task4); + + std::packaged_task task5{f1l}; + check_type>(task5); + + std::packaged_task task6{f1ln}; + check_type>(task6); + + std::packaged_task task5a{std::move(task5)}; + check_type>(task5a); + + std::packaged_task task6a{std::move(task6)}; + check_type>(task6a); +} + +struct X { + int operator()(const short&, void*); +}; + +struct Y { + void operator()(int) const & noexcept; +}; + +void +test02() +{ + X x; + std::packaged_task task1{x}; + check_type>(task1); + + Y y; + std::packaged_task task2{y}; + check_type>(task2); + + std::packaged_task task3{[&x](float) -> X& { return x; }}; + check_type>(task3); +} -- 2.34.1