Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic lambdas with statically sized arrays as arguments

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'
like image 546
Petter Avatar asked Aug 27 '17 08:08

Petter


1 Answers

It is illegal.

[dcl.array]/1, emphasis mine:

In a declaration T D where D has the form

D1 [ constant-expressionopt ] attribute-specifier-seqopt

and the type of the identifier in the declaration T D1 is “derived-declarator-type-list T”, then the type of the identifier of D is an array type; if the type of the identifier of D contains the auto type-specifier, the program is ill-formed.

like image 176
cpplearner Avatar answered Sep 24 '22 03:09

cpplearner