This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/80789] New: Better error for passing lambda with capture as function pointer
- From: "denis.campredon at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 16 May 2017 19:08:47 +0000
- Subject: [Bug c++/80789] New: Better error for passing lambda with capture as function pointer
- Auto-submitted: auto-generated
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