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.
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.
That would be completely bogus. I hope gcc doesn't do this. It's clearly a bug. W.
Not if it was not on purpose as an extension of C which is tottally likely because C does not have empty structs.
Confirmed, not a regression (assuming the bug report is valid in the first place - I don't know C standard that well):
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).
Subject: Bug 17188 CVSROOT: /cvs/gcc Module name: gcc Changes by: jsm28@gcc.gnu.org 2004-09-24 17:22:20 Modified files: gcc : ChangeLog c-decl.c gcc/testsuite : ChangeLog gcc/testsuite/gcc.dg: decl-3.c Added files: gcc/testsuite/gcc.dg: nested-redef-1.c pr17188-1.c Log message: PR c/17188 * c-decl.c (diagnose_mismatched_decls): Check for duplicate declarations of enumerators. (start_struct): Check TYPE_SIZE rather than TYPE_FIELDS to check for redefinition. Check for nested redefinition. (finish_struct): Don't check for nested redefinition. (start_enum): Check for nested redefinition. testsuite: * gcc.dg/nested-redef-1.c, gcc.dg/pr17188-1.c: New tests. * gcc.dg/decl-3.c: Adjust expected message. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5603&r2=2.5604 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.588&r2=1.589 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4344&r2=1.4345 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/nested-redef-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr17188-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/decl-3.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
Fixed.
Subject: Bug 17188 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: jsm28@gcc.gnu.org 2005-07-28 23:01:31 Modified files: gcc : ChangeLog c-decl.c gcc/testsuite : ChangeLog gcc/testsuite/gcc.dg: decl-3.c Added files: gcc/testsuite/gcc.dg: nested-redef-1.c pr17188-1.c Log message: PR c/17188 PR c/21899 * c-decl.c (diagnose_mismatched_decls): Check for duplicate declarations of enumerators. (start_struct): Check TYPE_SIZE rather than TYPE_FIELDS to check for redefinition. Check for nested redefinition. (finish_struct): Don't check for nested redefinition. (start_enum): Check for nested redefinition. testsuite: * gcc.dg/nested-redef-1.c, gcc.dg/pr17188-1.c: New tests. * gcc.dg/decl-3.c: Adjust expected message. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.889&r2=2.2326.2.890 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.470.4.20&r2=1.470.4.21 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.414&r2=1.3389.2.415 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/nested-redef-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.60.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr17188-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.60.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/decl-3.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2&r2=1.2.4.1
Patch backported to 3.4 branch since bug 21899 showed some cases were regressions.