[clang] [clang] Redeclare function templates instances per primary template (PR #110387)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 29 22:54:02 PDT 2024
================
@@ -2146,9 +2147,15 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
FunctionDecl *SpecFunc
= FunctionTemplate->findSpecialization(Innermost, InsertPos);
- // If we already have a function template specialization, return it.
- if (SpecFunc)
- return SpecFunc;
+ if (SpecFunc) {
+ if (!SpecFunc->isTemplateInstantiation())
+ return SpecFunc;
+
+ for (auto *Redecl : SpecFunc->redecls())
+ if (Redecl->getPrimaryTemplate() == FunctionTemplate)
+ return Redecl;
+ }
+ PrevFunc = SpecFunc;
----------------
zyn0217 wrote:
Let me rephrase the purpose here:
So now clang instantiates a new function declaration as long as the previous instantiation doesn't exist / the previous instantiation has a distinct primary template declaration, right?
I feel I struggle to understand the benefit here, though it might indeed have fixed/improved something. Can you explain it more?
https://github.com/llvm/llvm-project/pull/110387
More information about the cfe-commits
mailing list