This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: GCC rejects valid code?
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Roberto Bagnara <bagnara at cs dot unipr dot it>
- Cc: gccbugs <gcc-bugs at gcc dot gnu dot org>
- Date: Thu, 24 Jan 2008 22:10:14 +0000 (UTC)
- Subject: Re: GCC rejects valid code?
- References: <4798FD7E.9070703@cs.unipr.it>
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