From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4445E3858436; Sat, 5 Feb 2022 22:46:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4445E3858436 From: "nickhuang99 at hotmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nickhuang99 at hotmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Feb 2022 22:46:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104358 --- Comment #2 from qingzhe huang --- Here are more tests (https://www.godbolt.org/z/5qc8jTGa8) to show that only msvc is giving the correct result.=20 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 using Lambda=3Ddecltype(+[](T){}); static_assert(is_same_v, void(*)(int)>);=20 2. The "foo" takes "Lambda" as parameter template T foo(T&&, Lambda);=20 3. As "Lambda" 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" signature as "int(*)(int&&, /*Lambda*/int)", this is not possible. static_assert(is_same_v), int(*)(int&&, int)>);=20 These are use cases for "foo": a) using lambda directly foo(5, [](int n){});// lambda conversion operator! b) using converted function pointer from lambda by operator "+" auto funptr=3D+[](int n){}; foo(5, funptr); c) directly using a function pointer void(*ptr)(int)=3Dfunptr; foo(5, ptr);=