The following testcase shows some inconsistency w.r.t zero-size arrays. Without "-pedantic" we diagnose the array(s) whose dimension is found via dependent lookup. ============================================== template<int> struct A { static const int i = 0; }; template<int N> struct B { int x[A<N>::i]; // error int y[A<0>::i]; // no error since 3.4.0 int z[0]; // no error }; B<0> b; ============================================== Depending on the point of view this is rejects-valid or accepts-invalid. Btw, with "-pedantic" we diagnose all three arrays.
Confirmed.
*** Bug 22243 has been marked as a duplicate of this bug. ***
On the 3.4 branch the situation changed with Giovanni's patch for PR19208: http://gcc.gnu.org/ml/gcc-cvs/2005-07/msg00902.html We now diagnose none of the arrays without "-pedantic", and all three arrays with "-pedantic". This matches the behavior for arrays in non-template structs and outside any struct. So I'd call this fixed on the 3.4 branch. The 4.0 branch and mainline still have the problem, though. Technically these are regressions now.
We all agree that in pedantic mode all three lines are erroneous, so let's just consider the non-pedantic case. We can choose not to be picky about the non-dependent declarations because such code makes the program ill-formed; accepting such a program clearly does not change the behavior of any conforming program. But, for dependent declarations, we must be careful of SFINAE. If we do not reject instantiations that create types where type deduction fails, we can change the meaning of conforming programs -- and the absence of -pedantic should never change the meaning of a conforming program. So, we must issue an error for the dependent cases. I think that the right fix for this is to make the use of this extension an unconditional pedwarn in GNU C++, instead of "if (pedantic) pedwarn (...)" as it is now. That would still allow people to use -fpermissive to allow non-dependent zero-length arrays.
There's an easy fix outlined in Comment #4; we should implement it.
Patch posted: http://gcc.gnu.org/ml/gcc-patches/2005-11/msg00164.html
And the changelog in http://gcc.gnu.org/ml/gcc-patches/2005-11/msg00165.html
I approved the patch.
Subject: Bug 19989 Author: jconner Date: Fri Nov 4 01:23:22 2005 New Revision: 106468 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106468 Log: PR c++/19989 cp/pt.c (tsubst): Accept zero-length array if tf_error is set in complain flags. Change error message for negative- length array. testsuite/g++.dg/ext/array2.C: New test. testsuite/g++.dg/template/dependent-name3.C: New test. testsuite/g++.dg/template/dependent-name4.C: New test. testsuite/g++.dg/template/sfinae2.C: New test. Added: trunk/gcc/testsuite/g++.dg/ext/array2.C trunk/gcc/testsuite/g++.dg/template/dependent-name3.C trunk/gcc/testsuite/g++.dg/template/dependent-name4.C trunk/gcc/testsuite/g++.dg/template/sfinae2.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 19989 Author: jconner Date: Fri Nov 4 01:55:36 2005 New Revision: 106471 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106471 Log: PR c++/19989 cp/pt.c (tsubst): Accept zero-length array if tf_error is set in complain flags. Change error message for negative- length array. testsuite/g++.dg/ext/array2.C: New test. testsuite/g++.dg/template/dependent-name3.C: New test. testsuite/g++.dg/template/dependent-name4.C: New test. testsuite/g++.dg/template/sfinae2.C: New test. Added: branches/gcc-4_0-branch/gcc/testsuite/g++.dg/ext/array2.C branches/gcc-4_0-branch/gcc/testsuite/g++.dg/template/dependent-name3.C branches/gcc-4_0-branch/gcc/testsuite/g++.dg/template/dependent-name4.C branches/gcc-4_0-branch/gcc/testsuite/g++.dg/template/sfinae2.C Modified: branches/gcc-4_0-branch/gcc/cp/ChangeLog branches/gcc-4_0-branch/gcc/cp/pt.c branches/gcc-4_0-branch/gcc/testsuite/ChangeLog
Fixed.