Generic lambdas with statically sized arrays as arguments

256 Views Asked by At

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'
1

There are 1 best solutions below

5
On BEST ANSWER

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.