[cfe-commits] MS anonymous struct patch

Jianjiang Ceng jianjiang.ceng at googlemail.com
Sun Feb 19 07:39:09 PST 2012


2012/2/19 Richard Smith <richard at metafoo.co.uk>:
> On Sat, Feb 18, 2012 at 9:37 PM, Jianjiang Ceng
> <jianjiang.ceng at googlemail.com> wrote:
>>
>> 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.
>
>
> I believe this extension should be enabled by MicrosoftMode rather than
> MicrosoftExt, since it alters the behavior of valid C code. However, I note
> that gcc's -fms-extensions enables it.

Exactly, this is why I think it makes sense to enable this also with clang's
-fms-extensions.

> Clang code has a line length limit of 80 columns; your patch has some lines
> longer than 80 that. Also, your testcase has a mixture of tabs and spaces.

Being a newbie in the community, there is no execuse not following the coding
style. The new patch is untabified.

> Index: lib/Sema/SemaDecl.cpp
> @@ -2954,7 +2955,7 @@
>    SmallVector<NamedDecl*, 2> Chain;
>    Chain.push_back(Anon);
>
> -  RecordDecl *RecordDef = Record->getDefinition();
> +  RecordDecl *RecordDef = Record->isCompleteDefinition() ? Record :
> Record->getDefinition();
>    if (!RecordDef || InjectAnonymousStructOrUnionMembers(*this, S,
> CurContext,
>                                                          RecordDef, AS_none,
>                                                          Chain, true))
>
> This change appears to be unnecessary.
>

The original development was done with the 3.0 release, where this change is
necessary. It seems the latest clang does not need it any more, and it's
removed from the patch.

> - Richard

Thanks for the comment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: anonymous_struct.patch
Type: application/octet-stream
Size: 1799 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120219/72cad51e/attachment.obj>


More information about the cfe-commits mailing list