17188 – struct Foo { } redefinition (original) (raw)
Description M Welinder 2004-08-25 18:27:18 UTC
When an empty structure or union is defined twice, no error is given.
struct Foo { }; struct Foo { };
gcc-3.4 -std=c99 -pedantic -Wall ~/foo.c /home/welinder/foo.c:1: warning: struct has no members /home/welinder/foo.c:2: warning: struct has no members
If I add members, say "int : 1;", I get
struct Foo { int : 1; }; struct Foo { int : 1; };
gcc-3.4 -std=c99 -pedantic -Wall ~/foo.c /home/welinder/foo.c:1: warning: struct has no named members /home/welinder/foo.c:2: error: redefinition of `struct Foo' /home/welinder/foo.c:2: warning: struct has no named members
And the mid-point would be...
struct Foo { }; struct Foo { int : 1; };
gcc-3.4 -std=c99 -pedantic -Wall ~/foo.c /home/welinder/foo.c:1: warning: struct has no members /home/welinder/foo.c:2: warning: struct has no named members
Note, that empty structures is a gcc extension.
Comment 1 Drea Pinski 2004-08-25 18:41:57 UTC
I don't know about the GCC extension that well but it looks to me that an empty struct is acting as the same as forward declaring the struct.
Comment 2 Wolfgang Bangerth 2004-08-25 22:41:40 UTC
That would be completely bogus. I hope gcc doesn't do this. It's clearly a bug.
W.
Comment 3 Drea Pinski 2004-08-25 23:32:40 UTC
Not if it was not on purpose as an extension of C which is tottally likely because C does not have empty structs.
Comment 4 Giovanni Bajo 2004-09-17 02:28:42 UTC
Confirmed, not a regression (assuming the bug report is valid in the first place - I don't know C standard that well):
Comment 5 Drea Pinski 2004-09-17 03:14:59 UTC
Since empty structs are extensions, this would then need to be invalid GNU C which it might mean anything then (and it might in fact be right to accept it).
Comment 7 Drea Pinski 2004-09-24 17:34:53 UTC
Fixed.
Comment 9 Joseph S. Myers 2005-07-28 23:10:15 UTC
Patch backported to 3.4 branch since bug 21899 showed some cases were regressions.