diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-03-10 18:52:44 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-03-10 18:52:44 +0000 |
commit | 27b152fa7443f4e24630b997c07def6b0c23925a (patch) | |
tree | 478ae818f13c3655240bf0805502c5ee12840331 /lib | |
parent | 98137534e612c274ba270af99d73429043957e53 (diff) |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/Sema.h | 14 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 10 |
2 files changed, 20 insertions, 4 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index c662301da3..d68924c7c0 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -243,7 +243,10 @@ public: /// 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 @@ public: 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. /// diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 4a12b07766..057b256ddd 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -56,7 +56,10 @@ Sema::InstantiatingTemplate::~InstantiatingTemplate() { /// \brief Post-diagnostic hook for printing the instantiation stack. void Sema::PrintInstantiationStackHook(unsigned, void *Cookie) { - static_cast<Sema*>(Cookie)->PrintInstantiationStack(); + Sema &SemaRef = *static_cast<Sema*>(Cookie); + SemaRef.PrintInstantiationStack(); + SemaRef.LastTemplateInstantiationErrorContext + = SemaRef.ActiveTemplateInstantiations.back().Entity; } /// \brief Prints the current instantiation stack through a series of @@ -503,7 +506,7 @@ Sema::InstantiateBaseSpecifiers( for (ClassTemplateSpecializationDecl::base_class_iterator Base = ClassTemplate->getTemplatedDecl()->bases_begin(), BaseEnd = ClassTemplate->getTemplatedDecl()->bases_end(); - Base != BaseEnd && !Invalid; ++Base) { + Base != BaseEnd; ++Base) { if (!Base->getType()->isDependentType()) { // FIXME: Allocate via ASTContext InstantiatedBases.push_back(new CXXBaseSpecifier(*Base)); @@ -533,7 +536,8 @@ Sema::InstantiateBaseSpecifiers( Invalid = true; } - if (AttachBaseSpecifiers(ClassTemplateSpec, &InstantiatedBases[0], + if (!Invalid && + AttachBaseSpecifiers(ClassTemplateSpec, &InstantiatedBases[0], InstantiatedBases.size())) Invalid = true; |