[PATCH] D31076: [change-namespace] do not rename specialized template parameters.

Eric Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 17 07:18:14 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL298090: [change-namespace] do not rename specialized template parameters. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D31076?vs=92135&id=92141#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31076

Files:
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
  clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp


Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
===================================================================
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
@@ -286,6 +286,15 @@
     return Node.isScoped();
 }
 
+bool isTemplateParameter(TypeLoc Type) {
+  while (!Type.isNull()) {
+    if (Type.getTypeLocClass() == TypeLoc::SubstTemplateTypeParm)
+      return true;
+    Type = Type.getNextTypeLoc();
+  }
+  return false;
+}
+
 } // anonymous namespace
 
 ChangeNamespaceTool::ChangeNamespaceTool(
@@ -833,6 +842,8 @@
   // Types of CXXCtorInitializers do not need to be fixed.
   if (llvm::is_contained(BaseCtorInitializerTypeLocs, Type))
     return;
+  if (isTemplateParameter(Type))
+    return;
   // The declaration which this TypeLoc refers to.
   const auto *FromDecl = Result.Nodes.getNodeAs<NamedDecl>("from_decl");
   // `hasDeclaration` gives underlying declaration, but if the type is
Index: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
===================================================================
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -2006,6 +2006,52 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, TypeAsTemplateParameter) {
+  std::string Code = "namespace na {\n"
+                     "struct X {};\n"
+                     "namespace nb {\n"
+                     "template <typename TT>\n"
+                     "void TempTemp(const TT& t) {\n"
+                     "  TT tmp;\n"
+                     "}\n"
+                     "template <typename T>\n"
+                     "void Temp(const T& t) {\n"
+                     "  T tmp = t;\n"
+                     "  TempTemp(tmp);\n"
+                     "  TempTemp(t);\n"
+                     "}\n"
+                     "void f() {\n"
+                     "  X x;\n"
+                     "  Temp(x);\n"
+                     "}\n"
+                     "} // namespace nb\n"
+                     "} // namespace na\n";
+  std::string Expected = "namespace na {\n"
+                         "struct X {};\n"
+                         "\n"
+                         "} // namespace na\n"
+                         "namespace x {\n"
+                         "namespace y {\n"
+                         "template <typename TT>\n"
+                         "void TempTemp(const TT& t) {\n"
+                         "  TT tmp;\n"
+                         "}\n"
+                         "template <typename T>\n"
+                         "void Temp(const T& t) {\n"
+                         "  T tmp = t;\n"
+                         "  TempTemp(tmp);\n"
+                         "  TempTemp(t);\n"
+                         "}\n"
+                         "void f() {\n"
+                         "  ::na::X x;\n"
+                         "  Temp(x);\n"
+                         "}\n"
+                         "} // namespace y\n"
+                         "} // namespace x\n";
+
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 } // anonymous namespace
 } // namespace change_namespace
 } // namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31076.92141.patch
Type: text/x-patch
Size: 3348 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170317/0a1c615a/attachment.bin>


More information about the cfe-commits mailing list