This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/80789] New: Better error for passing lambda with capture as function pointer


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

            Bug ID: 80789
           Summary: Better error for passing lambda with capture as
                    function pointer
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: denis.campredon at gmail dot com
  Target Milestone: ---

With the following code:

---------
void g(void (*)());

void f() {
    int x;
    g([x](){});
}
----------
gcc produce this error:

--------
main.cpp: In function 'void f()':

main.cpp:5:14: error: cannot convert 'f()::<lambda()>' to 'void (*)()' for
argument '1' to 'void g(void (*)())'

     g([x](){});
--------
It is not clear why the lambda is not accepted since calling g with a lambda
with no capture produce no error.

A better error would say something like:
'cannot convert a lambda with capture to function pointer'.

And maybe a hint telling to use a "std::function" instead.

Regards,
Denis

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]