Conclusion:
GCC and EDG are wrong; Clang and MSVC are correct. This code is well-formed (legal) under the C++23 standard.
Below is a complete example demonstrating this issue, along with an explanation of why GCC/EDG is rejection is incorrect.
Example
#include <iostream>
// Default template parameter N = 1
template<unsigned int N = 1>
void f1(const int (&)[N]) {
std::cout << "Called with N = " << N << " ";
}int main() {
f1({}); // Clang/MSVC: legal, N=1. GCC/EDG: compilation error.
f1<1>({}); // All compilers: legal (workaround: explicitly specify N)
}
On GCC, f1({}) produces the following error (excerpt):
error: no matching function for call to f1(<brace-enclosed initializer list>)
note: template argument deduction/substitution failed
Why GCC/EDG Are Wrong
The key lies in the template argument deduction rules. According to the standard is [temp.deduct.call]/2 clause:
If removing references and cv-qualifiers from P gives std::initializer_list<P′> or P′[N] and the argument is a non-empty initializer list, then deduction is performed element-wise; otherwise, the initializer list argument makes the parameter a non-deduced context.
The logic chain is as follows:
- {} is an empty initializer list, so N cannot be deduced from it—the parameter is in a non-deduced context.
- However, N has a default value 1. According to [temp.deduct]/general, when a template parameter is not deduced and has a default argument, the compiler should use that default value.
- Therefore, N is determined to be 1, and the function signature becomes void f1(const int (&)[1]).
- Finally, the compiler checks whether {} can initialize const int[1]. According to initialization rules, an empty initializer list can legally value-initialize an array, so the call is valid.
GCC/EDG is error lies in: they incorrectly attempted template argument deduction from an empty initializer list (the standard explicitly states this is a non-deduced context), which prevented the default template argument from being applied. Clang and MSVC correctly follow the standard is process.
Workaround (for developers)
If you must use GCC or EDG, you can explicitly specify the template argument to bypass this bug:
f1<1>({}); // Explicitly specify N=1, all compilers accept
GCC has related Bug reports tracking this issue (such as Bug 120758), but as of the current search results, no fix version information is available.