From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 919233858C2D; Tue, 27 Sep 2022 10:59:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 919233858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664276399; bh=2FiCWtWpGqxzAohbDu6l6y6KyNEdei6f/LHsNgXG1uM=; h=From:To:Subject:Date:From; b=cYd46w1FR2zBcyM7AoCqJ3ERx5tKbX9KCUSEHt7/Fp107umdmp+6CUtp1w77eUbBr qyd7wwvcCuX18/KnDVozsVXIAze68f/bwUfuR4rQtwMwyEAB6A+Js1LtDFKQWAe28r subAA+z3dqcxAR4i5ydCeDAe87njpl9GEJI5fLCk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-2897] libstdc++: Adjust deduction guides for static operator() [PR106651] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: b939a5cc4143908ddda4b85a848c313136ff6e0c X-Git-Newrev: 614e5696d730a65998ff5b0373f905795a758dd6 Message-Id: <20220927105959.919233858C2D@sourceware.org> Date: Tue, 27 Sep 2022 10:59:59 +0000 (GMT) List-Id: https://gcc.gnu.org/g:614e5696d730a65998ff5b0373f905795a758dd6 commit r13-2897-g614e5696d730a65998ff5b0373f905795a758dd6 Author: Jonathan Wakely Date: Tue Sep 27 11:25:51 2022 +0100 libstdc++: Adjust deduction guides for static operator() [PR106651] 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. Diff: --- 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(-) 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); +}