Index: clang-rename/USRFinder.cpp =================================================================== --- clang-rename/USRFinder.cpp +++ clang-rename/USRFinder.cpp @@ -77,6 +77,10 @@ const auto TypeBeginLoc = Loc.getBeginLoc(); const auto TypeEndLoc = Lexer::getLocForEndOfToken( TypeBeginLoc, 0, Context.getSourceManager(), Context.getLangOpts()); + if (const auto *TemplateTypeParm = + dyn_cast(Loc.getType())) { + return setResult(TemplateTypeParm->getDecl(), TypeBeginLoc, TypeEndLoc); + } return setResult(Loc.getType()->getAsCXXRecordDecl(), TypeBeginLoc, TypeEndLoc); } Index: clang-rename/USRLocFinder.cpp =================================================================== --- clang-rename/USRLocFinder.cpp +++ clang-rename/USRLocFinder.cpp @@ -104,6 +104,12 @@ USRSet.end()) { checkAndAddLocation(Loc.getBeginLoc()); } + if (const auto *TemplateTypeParm = + dyn_cast(Loc.getType())) { + if (USRSet.find(getUSRForDecl(TemplateTypeParm->getDecl())) != USRSet.end()) { + checkAndAddLocation(Loc.getBeginLoc()); + } + } return true; } Index: test/clang-rename/TemplateTypenameFindByTemplateParam.cpp =================================================================== --- test/clang-rename/TemplateTypenameFindByTemplateParam.cpp +++ test/clang-rename/TemplateTypenameFindByTemplateParam.cpp @@ -1,11 +1,7 @@ // RUN: cat %s > %t.cpp -// RUN: clang-rename -offset=270 -new-name=U %t.cpp -i -- +// RUN: clang-rename -offset=147 -new-name=U %t.cpp -i -- // RUN: sed 's,//.*,,' %t.cpp | FileCheck %s -// Currently unsupported test. -// FIXME: clang-rename should be able to rename template parameters correctly. -// XFAIL: * - template // CHECK: template class Foo { T foo(T arg, T& ref, T* ptr) { // CHECK: U foo(U arg, U& ref, U* ptr) { Index: test/clang-rename/TemplateTypenameFindByTypeInside.cpp =================================================================== --- test/clang-rename/TemplateTypenameFindByTypeInside.cpp +++ test/clang-rename/TemplateTypenameFindByTypeInside.cpp @@ -1,11 +1,7 @@ // RUN: cat %s > %t.cpp -// RUN: clang-rename -offset=350 -new-name=U %t.cpp -i -- +// RUN: clang-rename -offset=227 -new-name=U %t.cpp -i -- // RUN: sed 's,//.*,,' %t.cpp | FileCheck %s -// Currently unsupported test. -// FIXME: clang-rename should be able to rename template parameters correctly. -// XFAIL: * - template // CHECK: template class Foo { T foo(T arg, T& ref, T* ptr) { // CHECK: U foo(U arg, U& ref, U* ptr) {