Is the following generic (polymorphic) lambda legal C++14?
auto f = [](auto x[3]) {
x[0];
x[1];
// etc.
};
GCC and Clang 4 accept the code, but Visual Studio 2017 does not. Is it legal?
error C3318: 'auto [3]': an array cannot have an element type that contains 'auto'
It is illegal.
[dcl.array]/1, emphasis mine:
In a declaration T D where D has the form
D1 [ constant-expressionopt ] attribute-specifier-seqoptand the type of the identifier in the declaration
T D1
is “derived-declarator-type-listT
”, then the type of the identifier ofD
is an array type; if the type of the identifier ofD
contains theauto
type-specifier, the program is ill-formed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With