[PATCH] D39241: [clang-rename] Fix and enable the failing TemplatedClassFunction test.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 24 06:52:26 PDT 2017


hokein created this revision.
Herald added a subscriber: klimek.

https://reviews.llvm.org/D39241

Files:
  lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
  test/clang-rename/TemplatedClassFunction.cpp


Index: test/clang-rename/TemplatedClassFunction.cpp
===================================================================
--- test/clang-rename/TemplatedClassFunction.cpp
+++ test/clang-rename/TemplatedClassFunction.cpp
@@ -6,17 +6,14 @@
 
 int main(int argc, char **argv) {
   A<int> a;
-  a.foo();   /* Test 2 */     // CHECK: a.bar()   /* Test 2 */
+  a.foo();   /* Test 2 */     // CHECK: a.bar();   /* Test 2 */
   return 0;
 }
 
 // Test 1.
-// RUN: clang-refactor rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+// RUN: clang-rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
 // Test 2.
-// RUN: clang-refactor rename -offset=162 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
-//
-// Currently unsupported test.
-// XFAIL: *
+// RUN: clang-rename -offset=162 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
 
 // To find offsets after modifying the file, use:
 //   grep -Ubo 'foo.*' <file>
Index: lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===================================================================
--- lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -73,6 +73,13 @@
         if (checkIfOverriddenFunctionAscends(OverriddenMethod))
           USRSet.insert(getUSRForDecl(OverriddenMethod));
       }
+
+      // If MethodDecl is an instantiated member function of a class template
+      // specialiazation, we also need to add the USR of the template member
+      // function from which MethodDecl is instantiated, otherwise the template
+      // member function would not be renamed.
+      if (const auto *FT = MethodDecl->getInstantiatedFromMemberFunction())
+        USRSet.insert(getUSRForDecl(FT));
     } else if (const auto *RecordDecl = dyn_cast<CXXRecordDecl>(FoundDecl)) {
       handleCXXRecordDecl(RecordDecl);
     } else if (const auto *TemplateDecl =
@@ -84,9 +91,16 @@
     return std::vector<std::string>(USRSet.begin(), USRSet.end());
   }
 
+  bool shouldVisitTemplateInstantiations() const { return true; }
+
   bool VisitCXXMethodDecl(const CXXMethodDecl *MethodDecl) {
     if (MethodDecl->isVirtual())
       OverriddenMethods.push_back(MethodDecl);
+    // If FoundDecl is a template member function, all corresponding
+    // instantiated member functions should be included, otherwise only the
+    // template member function would be renamed.
+    if (MethodDecl->getInstantiatedFromMemberFunction() == FoundDecl)
+      USRSet.insert(getUSRForDecl(MethodDecl));
     return true;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39241.120070.patch
Type: text/x-patch
Size: 2561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171024/28da97ce/attachment.bin>


More information about the cfe-commits mailing list