2020#include " clang/AST/ExprCXX.h"
2121#include " clang/AST/PrettyDeclStackTrace.h"
2222#include " clang/AST/TypeLoc.h"
23+ #include " clang/Basic/DiagnosticParse.h"
2324#include " clang/Basic/SourceManager.h"
2425#include " clang/Basic/TargetInfo.h"
2526#include " clang/Sema/EnterExpressionEvaluationContext.h"
3435#include " clang/Sema/SemaSwift.h"
3536#include " clang/Sema/Template.h"
3637#include " clang/Sema/TemplateInstCallback.h"
38+ #include " llvm/Support/Signals.h"
3739#include " llvm/Support/TimeProfiler.h"
3840#include < optional>
3941
@@ -5052,12 +5054,15 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
50525054 PatternDef = nullptr ;
50535055 }
50545056
5057+ // True is the template definition is unreachable, otherwise false.
5058+ bool Unreachable = false ;
50555059 // FIXME: We need to track the instantiation stack in order to know which
50565060 // definitions should be visible within this instantiation.
5057- if (DiagnoseUninstantiableTemplate (PointOfInstantiation, Function,
5058- Function->getInstantiatedFromMemberFunction (),
5059- PatternDecl, PatternDef, TSK,
5060- /* Complain*/ DefinitionRequired)) {
5061+ if (DiagnoseUninstantiableTemplate (
5062+ PointOfInstantiation, Function,
5063+ Function->getInstantiatedFromMemberFunction (), PatternDecl,
5064+ PatternDef, TSK,
5065+ /* Complain*/ DefinitionRequired, &Unreachable)) {
50615066 if (DefinitionRequired)
50625067 Function->setInvalidDecl ();
50635068 else if (TSK == TSK_ExplicitInstantiationDefinition ||
@@ -5082,11 +5087,16 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
50825087 if (AtEndOfTU && !getDiagnostics ().hasErrorOccurred () &&
50835088 !getSourceManager ().isInSystemHeader (PatternDecl->getBeginLoc ())) {
50845089 Diag (PointOfInstantiation, diag::warn_func_template_missing)
5085- << Function;
5086- Diag (PatternDecl->getLocation (), diag::note_forward_template_decl);
5087- if (getLangOpts ().CPlusPlus11 )
5088- Diag (PointOfInstantiation, diag::note_inst_declaration_hint)
5089- << Function;
5090+ << Function;
5091+ if (Unreachable) {
5092+ Diag (PatternDecl->getLocation (),
5093+ diag::note_unreachable_template_decl);
5094+ } else {
5095+ Diag (PatternDecl->getLocation (), diag::note_forward_template_decl);
5096+ if (getLangOpts ().CPlusPlus11 )
5097+ Diag (PointOfInstantiation, diag::note_inst_declaration_hint)
5098+ << Function;
5099+ }
50905100 }
50915101 }
50925102
0 commit comments