public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-8752] libstdc++: Make std::function deduction guide support explicit object functions [PR113335] Date: Fri, 2 Feb 2024 14:42:57 +0000 (GMT) [thread overview] Message-ID: <20240202144257.966263858034@sourceware.org> (raw) https://gcc.gnu.org/g:6f75149488b74ae696788b8761d6fcfa754a0af7 commit r14-8752-g6f75149488b74ae696788b8761d6fcfa754a0af7 Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Feb 2 10:03:12 2024 +0000 libstdc++: Make std::function deduction guide support explicit object functions [PR113335] This makes the deduction guides for std::function and std::packaged_task work for explicit object member functions, i.e. "deducing this", as per LWG 3617. libstdc++-v3/ChangeLog: PR libstdc++/113335 * include/bits/std_function.h (__function_guide_helper): Add partial specialization for explicit object member functions, as per LWG 3617. * testsuite/20_util/function/cons/deduction_c++23.cc: Check explicit object member functions. * testsuite/30_threads/packaged_task/cons/deduction_c++23.cc: Likewise. Diff: --- libstdc++-v3/include/bits/std_function.h | 6 ++++ .../20_util/function/cons/deduction_c++23.cc | 35 ++++++++++++++++++++++ .../packaged_task/cons/deduction_c++23.cc | 35 ++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/libstdc++-v3/include/bits/std_function.h b/libstdc++-v3/include/bits/std_function.h index 9130f9d28e30..79b59466fe9d 100644 --- a/libstdc++-v3/include/bits/std_function.h +++ b/libstdc++-v3/include/bits/std_function.h @@ -697,6 +697,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > { using type = _Res(_Args...); }; +#if __cpp_explicit_this_parameter >= 202110L + template<typename _Res, typename _Tp, bool _Nx, typename... _Args> + struct __function_guide_helper<_Res (*) (_Tp, _Args...) noexcept(_Nx)> + { using type = _Res(_Args...); }; +#endif + #if __cpp_static_call_operator >= 202207L && __cpp_concepts >= 202002L template<typename _StaticCallOp> struct __function_guide_static_helper 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 index 132bfb8fbfe4..8c70c1029296 100644 --- a/libstdc++-v3/testsuite/20_util/function/cons/deduction_c++23.cc +++ b/libstdc++-v3/testsuite/20_util/function/cons/deduction_c++23.cc @@ -21,3 +21,38 @@ test_static_call_operator() std::function func2 = F2{}; check_type<std::function<float(char, void*)>>(func2); } + +void +test_explicit_object_call_operator() +{ + // LWG 3617 - function/packaged_task deduction guides and deducing this + struct F { + int operator()(this const F&) { return 42; } + }; + + std::function g = F{}; + check_type<std::function<int()>>(g); + + struct F2 { + short operator()(this F2&, float&) { return 0; } + }; + + std::function g2 = F2{}; + check_type<std::function<short(float&)>>(g2); + + struct F3 { + void operator()(this const F3, char*, long) { } + }; + + std::function g3 = F3{}; + check_type<std::function<void(char*, long)>>(g3); + + struct F4 { + int i; + operator const int&() const { return i; } + const long& operator()(this int, const long& l) { return l; } + }; + + std::function g4 = F4{}; + check_type<std::function<const long&(const long&)>>(g4); +} 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 index 6a43cf945d88..307522a73f5d 100644 --- 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 @@ -20,3 +20,38 @@ test_static_call_operator() std::packaged_task task2{ F2{} }; check_type<std::packaged_task<float(char, void*)>>(task2); } + +void +test_explicit_object_call_operator() +{ + // LWG 3617 - function/packaged_task deduction guides and deducing this + struct F { + int operator()(this const F&) { return 42; } + }; + + std::packaged_task g{ F{} }; + check_type<std::packaged_task<int()>>(g); + + struct F2 { + short operator()(this F2&, float&) { return 0; } + }; + + std::packaged_task g2{ F2{} }; + check_type<std::packaged_task<short(float&)>>(g2); + + struct F3 { + void operator()(this const F3, char*, long) { } + }; + + std::packaged_task g3{ F3{} }; + check_type<std::packaged_task<void(char*, long)>>(g3); + + struct F4 { + int i; + operator const int&() const { return i; } + const long& operator()(this int, const long& l) { return l; } + }; + + std::packaged_task g4{ F4{} }; + check_type<std::packaged_task<const long&(const long&)>>(g4); +}
reply other threads:[~2024-02-02 14:42 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240202144257.966263858034@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).