GCC rejects valid code?
Joseph S. Myers
joseph@codesourcery.com
Thu Jan 24 22:38:00 GMT 2008
On Thu, 24 Jan 2008, Roberto Bagnara wrote:
> While looking at the rules governing struct/union declarations in C, I
> stumbled
> upon this example:
>
> union A {
> int i;
> float f;
> };
>
> void
> foo(struct A** p) {
> *p = 0;
> }
>
> This is accepted by both Comeau and the Intel C compiler, but is rejected
> by GCC 4.1.2 and 4.3.0 on the grounds that
>
> bug.c:7: error: ‘A’ defined as wrong kind of tag
>
> My interpretation is that line 7 does not define `union A' with the
> wrong kind of tag; it declares a (totally unrelated) `struct A'.
> However, I am not sure. Should I file a bug report for this?
Tags have a single namespace, not three namespaces. Because a declaration
of the tag A is visible when "struct A" is used, and "struct A** p" does
not define the contents of the type and is not just "struct A;", it refers
to the previous type of that tag (6.7.2.3#9, paragraph numbering from
N1256). Referring to a union type with "struct" in turn violates
paragraph 2 (added in C99 TC3 following DR#251).
--
Joseph S. Myers
joseph@codesourcery.com
More information about the Gcc-bugs
mailing list