[PATCH] D39120: [rename] Don't overwrite the template argument when renaming a template function.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 20 06:44:00 PDT 2017
hokein updated this revision to Diff 119654.
hokein marked an inline comment as done.
hokein added a comment.
Test for `foo <int>()`.
https://reviews.llvm.org/D39120
Files:
lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
unittests/Rename/RenameFunctionTest.cpp
Index: unittests/Rename/RenameFunctionTest.cpp
===================================================================
--- unittests/Rename/RenameFunctionTest.cpp
+++ unittests/Rename/RenameFunctionTest.cpp
@@ -220,6 +220,25 @@
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 {
Index: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
===================================================================
--- lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -221,7 +221,12 @@
}
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39120.119654.patch
Type: text/x-patch
Size: 1865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171020/06e650f5/attachment.bin>
More information about the cfe-commits
mailing list