<div dir="ltr">Ping.</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">Thanks,<br>--Serge<br></div></div>
<br><div class="gmail_quote">2015-03-12 13:23 GMT+06:00 Serge Pavlov <span dir="ltr"><<a href="mailto:sepavloff@gmail.com" target="_blank">sepavloff@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If class is absent from instantiation and is incomplete, instantiate it as<br>
incomplete class thus avoiding compiler crash.<br>
This change fixes PR18653.<br>
<br>
<a href="http://reviews.llvm.org/D8281" target="_blank">http://reviews.llvm.org/D8281</a><br>
<br>
Files:<br>
  lib/Sema/SemaTemplateInstantiate.cpp<br>
  lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
  test/SemaTemplate/instantiate-local-class.cpp<br>
<br>
Index: lib/Sema/SemaTemplateInstantiate.cpp<br>
===================================================================<br>
--- lib/Sema/SemaTemplateInstantiate.cpp<br>
+++ lib/Sema/SemaTemplateInstantiate.cpp<br>
@@ -2792,6 +2792,12 @@<br>
       isa<TemplateTemplateParmDecl>(D))<br>
     return nullptr;<br>
<br>
+  // If the declaration we are looking for is an incomplete type declaration, we<br>
+  // may not have a chance to instantiate it.<br>
+  if (const TypeDecl *TD = dyn_cast<TypeDecl>(D))<br>
+    if (TD->getTypeForDecl()->isIncompleteType())<br>
+      return nullptr;<br>
+<br>
   // If we didn't find the decl, then we either have a sema bug, or we have a<br>
   // forward reference to a label declaration.  Return null to indicate that<br>
   // we have an uninstantiated label.<br>
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
===================================================================<br>
--- lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
@@ -4399,6 +4399,15 @@<br>
         isa<TemplateTemplateParmDecl>(D))<br>
       return D;<br>
<br>
+    // If the declaration we are looking for is an incomplete type declaration,<br>
+    // we may not have a chance to instantiate it.<br>
+    if (const TypeDecl *TD = dyn_cast<TypeDecl>(D))<br>
+      if (TD->getTypeForDecl()->isIncompleteType()) {<br>
+        Decl *Inst = SubstDecl(D, CurContext, TemplateArgs);<br>
+        CurrentInstantiationScope->InstantiatedLocal(D, Inst);<br>
+        return cast<TypeDecl>(Inst);<br>
+      }<br>
+<br>
     if (D->isInvalidDecl())<br>
       return nullptr;<br>
<br>
Index: test/SemaTemplate/instantiate-local-class.cpp<br>
===================================================================<br>
--- test/SemaTemplate/instantiate-local-class.cpp<br>
+++ test/SemaTemplate/instantiate-local-class.cpp<br>
@@ -194,3 +194,13 @@<br>
   void f() { F<int>(); }<br>
 };<br>
 }<br>
+<br>
+namespace PR18653 {<br>
+  template <class T> void f();<br>
+  template <class T> struct str {<br>
+    void m() {<br>
+      f<class newclass>();<br>
+    }<br>
+  };<br>
+  template struct str<int>;<br>
+}<br>
<br>
EMAIL PREFERENCES<br>
  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
</blockquote></div><br></div>