The following snippet makes GCC 4.3.2 (and SVN versions as of 09/2008 still) cause an ICE: template <typename T, T N> void f(T(&)[N]); int main() { int x[2]; unsigned int y[2]; f(x); // works f(y); // ICE } Getting this output: test.cpp: In function 'int main()': test.cpp:7: internal compiler error: in dependent_type_p, at cp/pt.c:15585 More information about this issue: http://stackoverflow.com/questions/472530/how-to-pass-an-array-size-as-a-template-with-template-type
Confirmed. This used to work in 4.1 where we got the following error (which does not earn the prize for the prettiest error message ever): g/x> /home/bangerth/bin/gcc-4.1.1/bin/c++ -c x.cc x.cc: In function 'int main()': x.cc:7: error: size of array has non-integral type 'T' x.cc:1: error: size of array has non-integral type 'T' x.cc:1: error: size of array has non-integral type 'T' x.cc:7: error: invalid initialization of reference of type 'unsigned int (&)[1]' from expression of type 'unsigned int [2]' x.cc:1: error: in passing argument 1 of 'void f(T (&)[N]) [with T = unsigned int, T N = ((T)2)]' x.cc: In function 'void f(T (&)[N]) [with T = unsigned int, T N = ((T)2)]': x.cc:7: instantiated from here x.cc:1: error: size of array has non-integral type 'T'
Thinking some more about it, I believe that the code is actually valid. icc accepts it, for comparison. W.
3.3.6 and 3.4.1 accept it, starting with 3.4.2 we reject it and since 4.2.0 we ICE.
Yes, sorry for not mentioning it. I also think the code is valid. In the link to stackoverflow.com, where i answered that guys question, i gave reasons why i think so. Next time i will put what i think about that directly into the bugreport :)
Subject: Bug 38950 Author: jason Date: Thu Feb 12 22:40:37 2009 New Revision: 144139 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144139 Log: PR c++/38950 * pt.c (unify)[TEMPLATE_PARM_INDEX]: Convert to the tsubsted type. Added: trunk/gcc/testsuite/g++.dg/template/array20.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 38950 Author: jason Date: Tue Feb 17 18:27:32 2009 New Revision: 144239 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144239 Log: PR c++/38950 * pt.c (unify)[TEMPLATE_PARM_INDEX]: Convert to the tsubsted type. Added: branches/gcc-4_3-branch/gcc/testsuite/g++.dg/template/array20.C - copied unchanged from r144139, trunk/gcc/testsuite/g++.dg/template/array20.C Modified: branches/gcc-4_3-branch/gcc/cp/ChangeLog branches/gcc-4_3-branch/gcc/cp/pt.c branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
Fixed.