[clang] 04284b5 - [clang][Sema][NFC] Share member template instantiation lookup (#239450)

via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 7 22:07:14 PST 2026


Author: Chen Miao
Date: 2026-11-08T14:07:09+08:00
New Revision: 04284b5b7af985dfd985620e52de098b5ec892b8

URL: https://github.com/llvm/llvm-project/commit/04284b5b7af985dfd985620e52de098b5ec892b8
DIFF: https://github.com/llvm/llvm-project/commit/04284b5b7af985dfd985620e52de098b5ec892b8.diff

LOG: [clang][Sema][NFC] Share member template instantiation lookup (#239450)

Use `RedeclarableTemplateDecl` to consolidate the identical
`isInstantiationOf` implementations for class and function templates,
leaving the other overloads unchanged.

I initially considered turning these helpers into a function template,
but the declaration types use different accessors, such as
`getInstantiatedFromMemberTemplate()` and `getInstantiatedFromMember()`.

I'd also like to discuss whether a function template would be preferable
here, although that would likely require a broader change.

Added: 
    

Modified: 
    clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index fd9ff2e9c3c628..9e277c902365f6 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -7050,21 +7050,8 @@ Sema::InstantiateMemInitializers(CXXConstructorDecl *New,
 
 // TODO: this could be templated if the various decl types used the
 // same method name.
-static bool isInstantiationOf(ClassTemplateDecl *Pattern,
-                              ClassTemplateDecl *Instance) {
-  Pattern = Pattern->getCanonicalDecl();
-
-  do {
-    Instance = Instance->getCanonicalDecl();
-    if (Pattern == Instance) return true;
-    Instance = Instance->getInstantiatedFromMemberTemplate();
-  } while (Instance);
-
-  return false;
-}
-
-static bool isInstantiationOf(FunctionTemplateDecl *Pattern,
-                              FunctionTemplateDecl *Instance) {
+static bool isInstantiationOf(RedeclarableTemplateDecl *Pattern,
+                              RedeclarableTemplateDecl *Instance) {
   Pattern = Pattern->getCanonicalDecl();
 
   do {


        


More information about the cfe-commits mailing list