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

Doug Gregor doug.gregor at gmail.com
Mon Nov 10 07:32:49 PST 2008


Hi Pierre,

On Sun, Nov 9, 2008 at 11:53 AM, Pierre d'Herbemont <pdherbemont at free.fr> wrote:
> 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.

As Eli said, this patch should really produce an error

> 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.

Yeah, this is an interesting issue... what happens if you try to
actually generate code for your example program? And execute the
function dummy()? Since we have code-generation support for most of C,
I'd like for implementation of new C features to support
code-generation from the start. Maybe it will just work, but I'm
guessing that if it *doesn't* work, we may have to consider extending
the AST more to make it work.

The option name "AllowUnnamedStructOrUnionInStructOrUnion" is really,
really long :)
I'd be inclined to remove this option. Instead, just allow this
extension unless NoExtensions is set. On a related note, anonymous
unions (but anonymous structs aren't) are legal in C++, so the patch
should reflect that.

  - Doug



More information about the cfe-dev mailing list