[Bug c/14366] New: variable previously declared `static' redeclared `extern' is valid ISO C - 3.4 and 3.5 regression

amylaar at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Mon Mar 1 16:55:00 GMT 2004


This testcase:

static int i;

void f ()
{
  extern int i;
}

used to compile with (at least) gcc versions 2.95.2, 2.96, and 3.2.
This was broken by this patch:

2003-04-14  Mark Mitchell  <mark@codesourcery.com>

        * c-decl.c (grokdeclarator): Reject extern redeclarations of
        static variables.

2003-04-14  Mark Mitchell  <mark@codesourcery.com>

        * gcc.c-torture/execute/scope-2.c: Move to ...
        * gcc.dg/noncompile/scope.c: .... here.


The ISO 9899:1990 standard says in 6.1.2.2 Linkages of identifiers:

If the declaration of an identifier for an object or a function contains the
storage class specifier extern, the identifier has the same linkage as any
visible declaration of the identifier with file scope.

Therefore, for 9899:1990 both my testcase and the old scope-2.c testcase
should pass.

In ISO 9899:1999 6.2.2 Linkage of identifiers 4 it says:

For an identifier declared with the storage-class specifier extern in a scope
in which a prior declaration of that identifier is visible, if the prior
declaration specifies internal or external linkage, the linkage of the
identifier at the later daclaration is the same as the linkage specified
at the prior declaration.  If no prior declaration is visible, or if the
prior declaration specifies no linkage, then the identifer has external
linkage.
... 7 If, within a translation unit, the same identifier appears both with
internal and external linkage, the behaviour is undefined.

Thus, for ISO 9899:1999, my testcase should still pass, as i has internal
linkage both times.  scope-2.c, on the other hand, has first internal, then
no, then external linkage for v, so the behavior is undefined for scope-2.c .

-- 
           Summary: variable previously declared `static' redeclared
                    `extern' is valid ISO C - 3.4 and 3.5 regression
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: amylaar at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,geoffk at geoffk dot
                    org,mark at codesourcery dot com,neil at daikokuya dot
                    co dot uk,zack at codesourcery dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14366



More information about the Gcc-bugs mailing list