Bug 19989 - [4.0/4.1 regression] Inconsistency with zero-sized arrays
Summary: [4.0/4.1 regression] Inconsistency with zero-sized arrays
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 minor
Target Milestone: 4.0.3
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: diagnostic, patch
: 22243 (view as bug list)
Depends on:
Blocks: 24671
  Show dependency treegraph
 
Reported: 2005-02-15 22:56 UTC by Volker Reichelt
Modified: 2005-11-04 04:51 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-10-10 05:01:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2005-02-15 22:56:02 UTC
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.
Comment 1 Andrew Pinski 2005-02-22 17:53:28 UTC
Confirmed.
Comment 2 Andrew Pinski 2005-06-30 06:11:32 UTC
*** Bug 22243 has been marked as a duplicate of this bug. ***
Comment 3 Volker Reichelt 2005-10-10 16:31:47 UTC
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.
Comment 4 Mark Mitchell 2005-10-18 06:28:40 UTC
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.
Comment 5 Mark Mitchell 2005-10-31 02:43:01 UTC
There's an easy fix outlined in Comment #4; we should implement it.
Comment 6 Andrew Pinski 2005-11-03 01:18:30 UTC
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2005-11/msg00164.html
Comment 7 Andrew Pinski 2005-11-03 01:18:54 UTC
And the changelog in
http://gcc.gnu.org/ml/gcc-patches/2005-11/msg00165.html
Comment 8 Mark Mitchell 2005-11-03 07:06:41 UTC
I approved the patch.
Comment 9 jconner 2005-11-04 01:23:30 UTC
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

Comment 10 jconner 2005-11-04 01:55:41 UTC
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

Comment 11 Andrew Pinski 2005-11-04 04:51:31 UTC
Fixed.