Bug 18799 - [3.4 Regression] error: static declaration of 'x' follows non-static declaration
Summary: [3.4 Regression] error: static declaration of 'x' follows non-static declaration
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2004-12-02 21:21 UTC by Markus F.X.J. Oberhumer
Modified: 2005-04-30 00:04 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.3 4.0.0
Known to fail: 3.4.3
Last reconfirmed: 2005-03-27 16:52:11


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus F.X.J. Oberhumer 2004-12-02 21:21:09 UTC
This code used to give a warning on gcc 3.2 and gcc 3.3, gcc 3.4 does not warn
at all, and current mainline 4.0 makes this an error.

What do the C89 and C99 standards actually say here ?

+ cat x.c
extern int x[];
static int x[2];
int *foo(void) { return x; }

+ gcc-3.2 -std=c89 -Wall -W -pedantic -c x.c
x.c:2: warning: static declaration for `x' follows non-static

+ gcc-3.3 -std=c89 -Wall -W -pedantic -c x.c
x.c:2: warning: static declaration for `x' follows non-static

+ gcc-3.4 -std=c89 -Wall -W -pedantic -c x.c

+ gcc-4.0 -std=c89 -Wall -W -pedantic -c x.c
x.c:2: error: static declaration of 'x' follows non-static declaration
x.c:1: error: previous declaration of 'x' was here

+ gcc-3.2 -std=c99 -Wall -W -pedantic -c x.c
x.c:2: warning: static declaration for `x' follows non-static

+ gcc-3.3 -std=c99 -Wall -W -pedantic -c x.c
x.c:2: warning: static declaration for `x' follows non-static

+ gcc-3.4 -std=c99 -Wall -W -pedantic -c x.c

+ gcc-4.0 -std=c99 -Wall -W -pedantic -c x.c
x.c:2: error: static declaration of 'x' follows non-static declaration
x.c:1: error: previous declaration of 'x' was here
Comment 1 Andrew Pinski 2004-12-02 21:24:00 UTC
The C standard says this is invalid code which is why 4.0.0 errors out.
Comment 2 Markus F.X.J. Oberhumer 2004-12-02 23:12:43 UTC
I'm reopening this against gcc-3.4.3 then, as the warning has vanished - a
possible regression against 3.2 and 3.3.

Note that gcc-3.4.3/gcc/c-decl.c talks about -Wtraditional, but even that
doesn't make the warning appear.

Please feel free to close this bug again if you disagree.


> gcc-3.3 -c -Wall -W -Wtraditional -pedantic x.c
x.c:2: warning: static declaration for `x' follows non-static
x.c: In function `foo':
x.c:3: warning: traditional C rejects ISO C style function definitions

> gcc-3.4.3 -c -Wall -W -Wtraditional -pedantic x.c
x.c: In function `foo':
x.c:3: warning: traditional C rejects ISO C style function definitions
Comment 3 Falk Hueffner 2004-12-03 09:13:04 UTC
Confirmed. I think we should even warn about this unconditionally and not
only with -pedantic.
Comment 4 Joseph S. Myers 2005-04-30 00:04:11 UTC
Fixed in 4.0.0.  c-decl.c in 3.4 was part way through a rewrite and
that intermediate version is fairly buggy and fragile, so backporting
fixes to that version seems inadvisable.