Add a notion of "post-diagnostic hooks", which are callbacks attached
to a diagnostic that will be invoked after the diagnostic (if it is
not suppressed). The hooks are allowed to produce additional
diagnostics (typically notes) that provide more information. We should
be able to use this to help diagnostic clients link notes back to the
diagnostic they clarify. Comments welcome; I'll write up documentation
and convert other clients (e.g., overload resolution failures) if
there are no screams of protest.
As the first client of post-diagnostic hooks, we now produce a
template instantiation backtrace when a failure occurs during template
instantiation. There's still more work to do to make this output
pretty, if that's even possible.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66557 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 1acd6b2..c662301 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -242,7 +242,10 @@
/// The primitive diagnostic helpers.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
- return Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
+ DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
+ if (!Diags.isBuiltinNote(DiagID) && !ActiveTemplateInstantiations.empty())
+ DB << PostDiagnosticHook(PrintInstantiationStackHook, this);
+ return DB;
}
virtual void DeleteExpr(ExprTy *E);
@@ -1719,6 +1722,9 @@
operator=(const InstantiatingTemplate&); // not implemented
};
+ static void PrintInstantiationStackHook(unsigned DiagID, void *Cookie);
+ void PrintInstantiationStack();
+
QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs,
unsigned NumTemplateArgs,
SourceLocation Loc, DeclarationName Entity);