This revision was automatically updated to reflect the committed changes.
Closed by commit rL316314: [rename] Don't overwrite the template argument when 
renaming a template… (authored by hokein).

Repository:
  rL LLVM

https://reviews.llvm.org/D39120

Files:
  cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
  cfe/trunk/unittests/Rename/RenameFunctionTest.cpp


Index: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
===================================================================
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ cfe/trunk/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
Index: cfe/trunk/unittests/Rename/RenameFunctionTest.cpp
===================================================================
--- cfe/trunk/unittests/Rename/RenameFunctionTest.cpp
+++ cfe/trunk/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: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
===================================================================
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ cfe/trunk/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
Index: cfe/trunk/unittests/Rename/RenameFunctionTest.cpp
===================================================================
--- cfe/trunk/unittests/Rename/RenameFunctionTest.cpp
+++ cfe/trunk/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 {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to