From 607f14168a8e424fe9f82640be26667f5c80098d Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 30 Mar 2010 20:35:20 +0000 Subject: [PATCH] Improve diagnostics when printing a template instantiation backtrace involving substitution of deduced template arguments into a class template partial specialization or function template, or when substituting explicitly-specific template arguments into a function template. We now print the actual deduced argument bindings so the user can see what got deduced. llvm-svn: 99923 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 8 ++++---- clang/lib/Sema/SemaTemplateInstantiate.cpp | 16 ++++++++++++++-- .../SemaTemplate/instantiate-function-params.cpp | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 58c40cf3380f..61f1048e51c9 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1385,13 +1385,13 @@ def note_default_function_arg_instantiation_here : Note< "for '%0' required here">; def note_explicit_template_arg_substitution_here : Note< "while substituting explicitly-specified template arguments into function " - "template %0, here">; + "template %0 %1">; def note_function_template_deduction_instantiation_here : Note< - "while substituting deduced template arguments into function template %0, " - "here">; + "while substituting deduced template arguments into function template %0 " + "%1">; def note_partial_spec_deduct_instantiation_here : Note< "during template argument deduction for class template partial " - "specialization %0, here">; + "specialization %0 %1">; def note_prior_template_arg_substitution : Note< "while substituting prior template arguments into %select{non-type|template}0" " template parameter%1 %2">; diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 4da1fcb9242e..d08f483a6a08 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -394,7 +394,11 @@ void Sema::PrintInstantiationStack() { = cast((Decl *)Active->Entity); Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), diag::note_explicit_template_arg_substitution_here) - << FnTmpl << Active->InstantiationRange; + << FnTmpl + << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), + Active->TemplateArgs, + Active->NumTemplateArgs) + << Active->InstantiationRange; break; } @@ -405,13 +409,21 @@ void Sema::PrintInstantiationStack() { Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), diag::note_partial_spec_deduct_instantiation_here) << Context.getTypeDeclType(PartialSpec) + << getTemplateArgumentBindingsText( + PartialSpec->getTemplateParameters(), + Active->TemplateArgs, + Active->NumTemplateArgs) << Active->InstantiationRange; } else { FunctionTemplateDecl *FnTmpl = cast((Decl *)Active->Entity); Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), diag::note_function_template_deduction_instantiation_here) - << FnTmpl << Active->InstantiationRange; + << FnTmpl + << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), + Active->TemplateArgs, + Active->NumTemplateArgs) + << Active->InstantiationRange; } break; diff --git a/clang/test/SemaTemplate/instantiate-function-params.cpp b/clang/test/SemaTemplate/instantiate-function-params.cpp index 14c4d9f933a7..ea8dd7061988 100644 --- a/clang/test/SemaTemplate/instantiate-function-params.cpp +++ b/clang/test/SemaTemplate/instantiate-function-params.cpp @@ -7,7 +7,7 @@ template struct if_ { }; template struct wrap_constraints { }; template -inline char has_constraints_(Model* , // expected-note 4{{while substituting}} \ +inline char has_constraints_(Model* , // expected-note 4{{while substituting deduced template arguments into function template 'has_constraints_' [with }} \ // expected-note 3{{candidate template ignored}} wrap_constraints* = 0); // expected-note 4{{in instantiation}}