After an error of any kind has occurred, don't assert when attempting
to find the instantiated declaration within a template instantiation
fails to do so. It's likely that the original instantiation got
dropped due to instantiation failures, which doesn't actually break
the invariants of the AST. This eliminates a number of
crash-on-invalid failures, e.g., PR9300.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127030 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 577c2c2..3473c87 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3031,9 +3031,11 @@
     }
 
     // UsingShadowDecls can instantiate to nothing because of using hiding.
-    assert((Result || isa<UsingShadowDecl>(D) || D->isInvalidDecl() ||
-            cast<Decl>(ParentDC)->isInvalidDecl())
-           && "Unable to find instantiation of declaration!");
+    // Note: this assertion end up firing in invalid code even when none of the 
+    // AST invariants have been broken, so we explicitly check whether any
+    // errors have been emitted
+    assert((Result || isa<UsingShadowDecl>(D) || Diags.hasErrorOccurred()) &&
+           "Unable to find instantiation of declaration!");
 
     D = Result;
   }