Edit: With the adoption of the resolution of CWG issue 1591 at the Committee's November 2014 meeting, the code in the OP is now allowed. The compiler can now deduce both the type and the number of elements in the array.
§14.8.2.5 [temp.deduct.type]/p5:
The non-deduced contexts are:
- [...]
- A function parameter for which the associated argument is an initializer list (8.5.4) but the parameter does not have
std::initializer_list or reference to possibly cv-qualified
std::initializer_list type.
- [...]
Your initializer list is a non-deduced context, so clang properly rejects your code.
Conceivably, g++ could support deduction in this case as an extension. However, as it rejects this code with a "deduced conflicting values" error:
template<unsigned N>
struct C { };
template <unsigned N>
void foo(C<N>, const int (&x)[N]) {}
int main(int argc, char *argv[])
{
foo(C<4>(), {1,2,3});
return 0;
}
It looks like a bug to me. (In the call to foo in the code above, the compiler is supposed to deduce N only from the first argument according to the standard, so there should be no conflict. g++ deduced N from the second argument as well, creating a conflict. This altered the behavior of a well-formed program, which isn't allowed for a conforming extension.)