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
The C standard says this is invalid code which is why 4.0.0 errors out.
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
Confirmed. I think we should even warn about this unconditionally and not only with -pedantic.
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.