[cfe-commits] MS anonymous struct patch

Jianjiang Ceng jianjiang.ceng at googlemail.com
Sat Feb 18 21:37:05 PST 2012


On Fri, Feb 17, 2012 at 11:56AM,"David Blaikie" <dblaikie at gmail.com>Wrote:
>
> On Fri, Feb 17, 2012 at 6:55 AM, Jianjiang Ceng
> <jianjiang.ceng at googlemail.com> wrote:
> > Hi all,
> >
> > please find the attached patch which should fix the problem of parsing
> > tagged anonymous structs, when ms-extensions is enabled.
> >
> > The following code can be parsed by the MS C compiler and GCC, but
> > clang gave an error on couldn't resolve the anonymous struct member
> > "c".
> >
> > struct a {
> >  struct b{
> >   int c;
> >  };
> > };
>
> I'm not sure I understand where the anonymity is here - is there a
> mistake in your example?

By default, GCC does not allow an anonymous struct to have a tag, i.e.
"b" in the example. If "-fms-extensions" is not enabled, GCC will
report that nothing is declared by the struct "b".

Things are a little bit different when MS extensions are allowed,
anonymous structs can have tags. Since they, as member in other
structs, still lack a name, they are anonymous. Therefore, the struct
member "c" in the example should not be referenced by struct_a.b.c,
but struct_a.c.

> Could you please include a valid test case in your patch?
>

The patch is updated with a test C file, anonymous-struct-ms.c, in test/Sema.

> >
> > void foo()
> > {
> >  struct a e;
> >  e.c = 0;
> > }
> >
> > This is my first patch submission here, any feedback would be welcome.
> >
> > Jianjiang Ceng
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >




More information about the cfe-commits mailing list