[cfe-dev] [PATCH] Allow unnamed structure or union fields within structs/unions in gnu99 mode

Eli Friedman eli.friedman at gmail.com
Sun Nov 9 11:01:15 PST 2008


On Sun, Nov 9, 2008 at 8:53 AM, Pierre d'Herbemont <pdherbemont at free.fr> wrote:
> Hi,
>
> This patch enables unnamed structure or union fields withing structs/unions
> when -std=gnu99 is used. Cf [1].
>
> Note, as stated in [1], struct { int a; union { int a; } } is discouraged,
> but won't produce any error nor warning.
> It is unclear for me that we really want to add anonymous structure support
> in RecordDecl::getMember, as implementation could vary given the language
> standard. Yet, not implementing here could lead to easy and unoticeable
> mistakes if the caller doesn't implement anonymous structure resolving.
>
> I'll be happy to ear your thoughts...

It looks generally fine to me.  It's probably a good idea for someone
else to review it, though.

A couple of small comments:

1. Do we want to support this extension in gnu89 mode?
2. Does this correctly deal with "struct foo {int a,b;}; struct bar
{int a; struct foo;};" and "struct bar {int a; struct foo {int
a,b;};};"?
3. For "struct { int a; union { int a; } }", can we produce an error?
The gcc docs seem to imply that's it's illegal, and it's usually
better to produce an error where we can.

-Eli



More information about the cfe-dev mailing list