Should lambda generic decay not be captured to use pointers?

Consider the following code:

int main() { auto l = [](auto){}; void(*p)(int) = l; } 

It works great with both GCC and clang .
Consider the following slightly modified version:

 int main() { auto l = [](auto...){}; void(*p)(int) = l; } 

In this case, clang still accepts it , while GCC rejects it .

Is there a reason this code should be rejected or is it a compiler error?


I am going to open the problem, but I would like to know if there is any proposal that could be implemented by one of them, and not the other.

+7
c ++ gcc clang c ++ 14 generic-lambda
source share
1 answer

This is a known GCC analysis error ( 64095 , 68071 ): [](auto...){} erroneously parsed as [](auto, ...) {} , not [](auto...x){} ; the ellipsis is parsed as varargs in C style, and does not declare a package of parameters (in terms of a legal language, it is parsed as part of a parameter-declaration-parameter, not an abstract-declarator, in violation of [dcl.fct] / 17 ).

It goes without saying that [](auto, ...){} does not convert to void (*)(int) .

The workaround is to give the package a name; if you do, you will see that the conversion compiles successfully.

+11
source share

All Articles