<div class="gmail_quote">On Sat, Feb 18, 2012 at 9:37 PM, Jianjiang Ceng <span dir="ltr"><<a href="mailto:jianjiang.ceng@googlemail.com">jianjiang.ceng@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Fri, Feb 17, 2012 at 11:56AM,"David Blaikie" <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>>Wrote:<br>
<div class="im">><br>
> On Fri, Feb 17, 2012 at 6:55 AM, Jianjiang Ceng<br>
> <<a href="mailto:jianjiang.ceng@googlemail.com">jianjiang.ceng@googlemail.com</a>> wrote:<br>
> > Hi all,<br>
> ><br>
> > please find the attached patch which should fix the problem of parsing<br>
> > tagged anonymous structs, when ms-extensions is enabled.<br>
> ><br>
> > The following code can be parsed by the MS C compiler and GCC, but<br>
> > clang gave an error on couldn't resolve the anonymous struct member<br>
> > "c".<br>
> ><br>
> > struct a {<br>
> >  struct b{<br>
> >   int c;<br>
> >  };<br>
> > };<br>
><br>
> I'm not sure I understand where the anonymity is here - is there a<br>
> mistake in your example?<br>
<br>
</div>By default, GCC does not allow an anonymous struct to have a tag, i.e.<br>
"b" in the example. If "-fms-extensions" is not enabled, GCC will<br>
report that nothing is declared by the struct "b".<br>
<br>
Things are a little bit different when MS extensions are allowed,<br>
anonymous structs can have tags. Since they, as member in other<br>
structs, still lack a name, they are anonymous. Therefore, the struct<br>
member "c" in the example should not be referenced by struct_a.b.c,<br>
but struct_a.c.</blockquote><div><br></div><div>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.</div>
<div><br></div><div>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.</div><div><br></div><div>Index: lib/Sema/SemaDecl.cpp</div>
<div><div>@@ -2954,7 +2955,7 @@</div><div>   SmallVector<NamedDecl*, 2> Chain;</div><div>   Chain.push_back(Anon);</div><div> </div><div>-  RecordDecl *RecordDef = Record->getDefinition();</div><div>+  RecordDecl *RecordDef = Record->isCompleteDefinition() ? Record : Record->getDefinition();</div>
<div>   if (!RecordDef || InjectAnonymousStructOrUnionMembers(*this, S, CurContext,</div><div>                                                         RecordDef, AS_none,</div><div>                                                         Chain, true))</div>
</div><div><br></div><div>This change appears to be unnecessary.</div><div><br></div><div>- Richard</div></div>