https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79957
Bug ID: 79957 Summary: [C++] Zero-length array function parameters in templates should cause warning/substituion failure in pedantic mode Product: gcc Version: 6.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: felix.morgner at gmail dot com Target Milestone: --- According to ISO14882 [dcl.array] zero-length arrays are not allowed: ... If the constant-expression (5.19) is present, it shall be a converted constant expression of type std::size_t and its value shall be greater than zero. ... GCC generally accepts zero-length arrays as an extension. However, it does handle them inconsitently when compiling in pedantic mode. The following code compiles fine in pedantic mode (for all code samples, the following flags are used: -Wall -Wextra -Werror -pedantic-errors): template<unsigned long long N> void fun(int [N] = {}) { } int main() { fun<0>(); } even though the parameter of fun will be a zero-length array. On the other hand, the following code does not compile in pedantic mode: void fun(int [0] = {}) { } int main() { fun(); } with the expected error message: array.cpp:1:21: error: ISO C++ forbids zero-size array [-Wpedantic] void fun(int [0] = {}) { Interestingly, the following code fails to compile as expected: template<unsigned long long N> void fun(int (*)[N] = {}) { } int main() { fun<0>(); } This incosistency leads to GCC interpreting the following code as being ambiguous: template<unsigned long long N> void fun(int [N + 1] = {}, int = 0) { } template<unsigned long long N> void fun(int [N] = {}) { } int main() { fun<0>(); } Handling zero-length array parameters in templates as invalid, when in pedantic mode, would make GCC SFINAE away the second fun(...). Both 'clang' and Microsoft's 'cl' handle zero-length arrays as expected.