public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104358] New: Assignable template lambda as function parameter is incorrectly reduced to type of "int"
@ 2022-02-03  1:24 nickhuang99 at hotmail dot com
  2022-02-03 20:14 ` [Bug c++/104358] " nickhuang99 at hotmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: nickhuang99 at hotmail dot com @ 2022-02-03  1:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104358

            Bug ID: 104358
           Summary: Assignable template lambda as function parameter is
                    incorrectly reduced to type of "int"
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nickhuang99 at hotmail dot com
  Target Milestone: ---

Please see code at https://www.godbolt.org/z/o3bxxsYPK
All other compilers parses this correctly.


#include <functional>
#include <type_traits>

using namespace std;

//1. I have a callback which happens to be an assignable lambda
template<typename T>
using Lambda=decltype(+[](T){});
//  which is esstially a function pointer 
static_assert(is_same_v<Lambda<int>, void(*)(int)>);

//2. Here is my data handle function which takes a data and the callback 
template<typename T>
auto foo(T&&, Lambda<T>)->T;

//3. However, parser consider the callback as type of "int"
static_assert( ! is_same_v<decltype(&foo<int>), int(*)(int&&, void(*)(int))>);
// lambda type is always considered as "int"
static_assert(is_same_v<decltype(&foo<int>), int(*)(int&&, int)>);
static_assert(is_same_v<decltype(&foo<bool>), bool(*)(bool&&, int)>);

// this is impossible as callback CANNOT be "int"
static_assert( ! is_same_v<Lambda<int>, int>);


////////////////////////////////////////////
//4. This won't happen for a traditional function pointer
template<typename T>
using FunPtr=void(*)(T);
static_assert(is_same_v<FunPtr<int>, void(*)(int)>);

//5. let's define a similar function with callback
template<typename T>
auto bar(T&&, FunPtr<T>)->T;
// there is no way for parser to consider callback as type of "int"
static_assert(is_same_v<decltype(&bar<int>), int(*)(int&&, void(*)(int))>);

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-27  5:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03  1:24 [Bug c++/104358] New: Assignable template lambda as function parameter is incorrectly reduced to type of "int" 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
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

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).