[clang] Reland: [clang] Track function template instantiation from definition (PR #125266)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 31 11:33:45 PST 2025
================
@@ -5276,9 +5277,31 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
RebuildTypeSourceInfoForDefaultSpecialMembers();
SetDeclDefaulted(Function, PatternDecl->getLocation());
} else {
+ NamedDecl *ND = Function;
+ DeclContext *DC = ND->getLexicalDeclContext();
+ std::optional<ArrayRef<TemplateArgument>> Innermost;
+ if (auto *Primary = Function->getPrimaryTemplate();
+ Primary &&
+ !isGenericLambdaCallOperatorOrStaticInvokerSpecialization(Function) &&
+ Function->getTemplateSpecializationKind() !=
+ TSK_ExplicitSpecialization) {
+ auto It = llvm::find_if(Primary->redecls(),
+ [](const RedeclarableTemplateDecl *RTD) {
+ return cast<FunctionTemplateDecl>(RTD)
+ ->isCompatibleWithDefinition();
+ });
+ assert(It != Primary->redecls().end() &&
+ "Should't get here without a definition");
+ if (FunctionDecl *Def = cast<FunctionTemplateDecl>(*It)
+ ->getTemplatedDecl()
+ ->getDefinition())
+ DC = Def->getLexicalDeclContext();
+ else
+ DC = (*It)->getLexicalDeclContext();
----------------
cor3ntin wrote:
Sorry, nevermind. I understand what you are doing now.
However, I'm wondering if we are not reinventing `getTemplateInstantiationPattern(true)` here, It looks strangely similar. Have you explored that?
https://github.com/llvm/llvm-project/pull/125266
More information about the cfe-commits
mailing list