https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69349
Bug ID: 69349 Summary: template substitution error for flexible array members Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- While working on a fix for bug 69251 I noticed the following problem. The following valid test case fails with both 5.3 and 6.0. It is accepted by Clang. $ cat x.c && /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -S -Wall -Wextra -Wpedantic -o/dev/null -xc++ x.c template <class> struct A; template <class T> struct A<T[]> { typedef int X; }; template <class T> int foo (T&, typename A<T>::X = 0) { return 0; } struct B { int n, a[]; }; void bar (B *b) { foo (b->a); } x.c: In function ‘void bar(B*)’: x.c:13:14: error: no matching function for call to ‘foo(int [])’ foo (b->a); ^ x.c:7:24: note: candidate: template<class T> int foo(T&, typename A<T>::X) template <class T> int foo (T&, typename A<T>::X = 0) { return 0; } ^~~ x.c:7:24: note: template argument deduction/substitution failed: x.c: In substitution of ‘template<class T> int foo(T&, typename A<T>::X) [with T = int []]’: x.c:13:14: required from here x.c:7:24: error: invalid use of incomplete type ‘struct A<int []>’ x.c:2:8: note: declaration of ‘struct A<int []>’ struct A; ^ G++ 5.3.0 gives a slightly different error because it treats flexible array members and zero-length arrays identically: x.c:9:21: warning: ISO C++ forbids zero-size array ‘a’ [-Wpedantic] struct B { int n, a[]; }; ^ x.c: In function ‘void bar(B*)’: x.c:13:14: error: no matching function for call to ‘foo(int [0])’ foo (b->a); ^ x.c:7:24: note: candidate: template<class T> int foo(T&, typename A<T>::X) template <class T> int foo (T&, typename A<T>::X = 0) { return 0; } ^ x.c:7:24: note: template argument deduction/substitution failed: x.c: In substitution of ‘template<class T> int foo(T&, typename A<T>::X) [with T = int [0]]’: x.c:13:14: required from here x.c:7:24: error: invalid use of incomplete type ‘struct A<int [0]>’ x.c:2:8: note: declaration of ‘struct A<int [0]>’ struct A; ^