Robustify instantiation of templates when there are errors in the
template definition. Do this both by being more tolerant of errors in
our asserts and by not dropping a variable declaration completely when
its initializer is ill-formed. Fixes the crash-on-invalid in PR6375,
but not the original issue.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97463 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 4405dcb..8a32f35 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -564,10 +564,10 @@
       }
 
       if (Init.isInvalid()) {
-        SkipUntil(tok::semi, true, true);
-        return DeclPtrTy();
-      }
-      Actions.AddInitializerToDecl(ThisDecl, move(Init));
+        SkipUntil(tok::comma, true, true);
+        Actions.ActOnInitializerError(ThisDecl);
+      } else
+        Actions.AddInitializerToDecl(ThisDecl, move(Init));
     }
   } else if (Tok.is(tok::l_paren)) {
     // Parse C++ direct initializer: '(' expression-list ')'
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 0fe9b7f..da192dd 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -3413,7 +3413,8 @@
 
     Decl *getInstantiationOf(const Decl *D) {
       Decl *Result = LocalDecls[D];
-      assert(Result && "declaration was not instantiated in this scope!");
+      assert((Result || D->isInvalidDecl()) && 
+             "declaration was not instantiated in this scope!");
       return Result;
     }
 
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 3d9899e..0f7bae8 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2323,7 +2323,8 @@
     }
 
     // UsingShadowDecls can instantiate to nothing because of using hiding.
-    assert((Result || isa<UsingShadowDecl>(D))
+    assert((Result || isa<UsingShadowDecl>(D) || D->isInvalidDecl() ||
+            cast<Decl>(ParentDC)->isInvalidDecl())
            && "Unable to find instantiation of declaration!");
 
     D = Result;