<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2015-04-07 2:23 GMT+06:00 Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">================<br>
Comment at: lib/Sema/SemaTemplateInstantiateDecl.cpp:4406-4407<br>
@@ +4405,4 @@<br>
<span class="">+      const TagDecl *DeclToInstantiate = nullptr;<br>
+      if (TagDecl *Def = TD->getDefinition())<br>
+        DeclToInstantiate = Def;<br>
+      else if (!TD->isThisDeclarationADefinition() && !TD->isFreeStanding())<br>
</span>----------------<br>
What's the purpose of this change? If we have a reference to a particular `TagDecl`, why don't we always instantiate that declaration?<br>
<div class=""><div class="h5"><br></div></div></blockquote><div>If check for invalid declaration is made prior to this one, it seems that we can always instantiate the type.</div><div>This fix however allows to compile the following code:</div><div><br></div><div><div>  template<typename T> void f3() {</div><div>    struct AA {</div><div>      struct x3 vvv;</div><div>    } xx;</div><div>    return xx.aaa;</div><div>    struct x3 { int aaa; };</div><div>  }</div></div><div><br></div><div>It is because at the point where incomplete type is used we instantiate its definition, which is defined later.Strange, but gcc also compiles this code. Not sure why this code should be accepted.</div><div><br></div><div>Thanks,</div><div>--Serge</div></div></div></div>