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(FoundDecl)) { handleCXXRecordDecl(RecordDecl); } else if (const auto *TemplateDecl = @@ -84,9 +91,16 @@ return std::vector(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; } 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 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.*'