public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "nickhuang99 at hotmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/104358] Assignable template lambda as function parameter is incorrectly reduced to type of "int" Date: Sat, 05 Feb 2022 22:46:42 +0000 [thread overview] Message-ID: <bug-104358-4-dpantXbss9@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-104358-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104358 --- Comment #2 from qingzhe huang <nickhuang99 at hotmail dot com> --- Here are more tests (https://www.godbolt.org/z/5qc8jTGa8) to show that only msvc is giving the correct result. It just illustrates the use cases of this definition and why it should be allowed. 1. By using operator "+", here the type "Lambda" is just a free function pointer. template<typename T> using Lambda=decltype(+[](T){}); static_assert(is_same_v<Lambda<int>, void(*)(int)>); 2. The "foo" takes "Lambda" as parameter template<typename T> T foo(T&&, Lambda<T>); 3. As "Lambda<T>" is just a function pointer, "foo" should allow both free function pointer or lambda(by conversion operator) to be used as argument. And because GCC mistakenly consider "foo<int>" signature as "int(*)(int&&, /*Lambda<int>*/int)", this is not possible. static_assert(is_same_v<decltype(&foo<int>), int(*)(int&&, int)>); These are use cases for "foo": a) using lambda directly foo<int>(5, [](int n){});// lambda conversion operator! b) using converted function pointer from lambda by operator "+" auto funptr=+[](int n){}; foo<int>(5, funptr); c) directly using a function pointer void(*ptr)(int)=funptr; foo<int>(5, ptr);
next prev parent reply other threads:[~2022-02-05 22:46 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-03 1:24 [Bug c++/104358] New: " nickhuang99 at hotmail dot com 2022-02-03 20:14 ` [Bug c++/104358] " nickhuang99 at hotmail dot com 2022-02-05 22:46 ` nickhuang99 at hotmail dot com [this message] 2022-10-27 5:21 ` [Bug c++/104358] signature of template function with template lambda(converted to function pointer) mistakenly regards it as " pinskia at gcc dot gnu.org
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=bug-104358-4-dpantXbss9@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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).