If we run into multiple errors within the same template instantiation,
only print the template instantiation backtrace for the first error.

Also, if a base class has failed to type-check during instantiation,
just drop that base class and continue on to check other base classes.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66563 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index c662301..d68924c 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -243,7 +243,10 @@
   /// The primitive diagnostic helpers.
   DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
     DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
-    if (!Diags.isBuiltinNote(DiagID) && !ActiveTemplateInstantiations.empty())
+    if (!Diags.isBuiltinNote(DiagID) && 
+        !ActiveTemplateInstantiations.empty() &&
+        ActiveTemplateInstantiations.back().Entity 
+          != LastTemplateInstantiationErrorContext)
       DB << PostDiagnosticHook(PrintInstantiationStackHook, this);
     return DB;
   }
@@ -1691,6 +1694,15 @@
   llvm::SmallVector<ActiveTemplateInstantiation, 16> 
     ActiveTemplateInstantiations;
 
+  /// \brief The last template from which a template instantiation
+  /// error or warning was produced.
+  ///
+  /// This value is used to suppress printing of redundant template
+  /// instantiation backtraces when there are multiple errors in the
+  /// same instantiation. FIXME: Does this belong in Sema? It's tough
+  /// to implement it anywhere else.
+  ClassTemplateSpecializationDecl *LastTemplateInstantiationErrorContext;
+
   /// \brief A stack object to be created when performing template
   /// instantiation.
   ///