Skip to content

Commit

Permalink
[rename] Don't overwrite the template argument when renaming a templa…
Browse files Browse the repository at this point in the history
…te function.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: cierpuchaw, cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D39120

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316314 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
hokein committed Oct 23, 2017
1 parent ef34bcb commit 4e7c062
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
}

auto StartLoc = Expr->getLocStart();
auto EndLoc = Expr->getLocEnd();
// For template function call expressions like `foo<int>()`, we want to
// restrict the end of location to just before the `<` character.
SourceLocation EndLoc = Expr->hasExplicitTemplateArgs()
? Expr->getLAngleLoc().getLocWithOffset(-1)
: Expr->getLocEnd();

// In case of renaming an enum declaration, we have to explicitly handle
// unscoped enum constants referenced in expressions (e.g.
// "auto r = ns1::ns2::Green" where Green is an enum constant of an unscoped
Expand Down
19 changes: 19 additions & 0 deletions unittests/Rename/RenameFunctionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,25 @@ TEST_F(RenameFunctionTest, RenameFunctionDecls) {
CompareSnippets(Expected, After);
}

TEST_F(RenameFunctionTest, RenameTemplateFunctions) {
std::string Before = R"(
namespace na {
template<typename T> T X();
}
namespace na { void f() { X<int>(); } }
namespace nb { void g() { na::X <int>(); } }
)";
std::string Expected = R"(
namespace na {
template<typename T> T Y();
}
namespace na { void f() { nb::Y<int>(); } }
namespace nb { void g() { Y<int>(); } }
)";
std::string After = runClangRenameOnCode(Before, "na::X", "nb::Y");
CompareSnippets(Expected, After);
}

TEST_F(RenameFunctionTest, RenameOutOfLineFunctionDecls) {
std::string Before = R"(
namespace na {
Expand Down

0 comments on commit 4e7c062

Please sign in to comment.