[clang] [clang] Redeclare function templates instances per primary template (PR #110387)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 30 14:52:34 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;
----------------
mizvekov wrote:

This fixes the case:
```C++
  cica(A<0>{}, 0);
  (void)A<1>{};
  cica(A<0>{}, 0);
```

As explained in the previous comment.

https://github.com/llvm/llvm-project/pull/110387


More information about the cfe-commits mailing list