[clang-tools-extra] r285549 - [change-namespace] fix namespace specifiers of template arguments.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 01:28:29 PDT 2016


Author: ioeric
Date: Mon Oct 31 03:28:29 2016
New Revision: 285549

URL: http://llvm.org/viewvc/llvm-project?rev=285549&view=rev
Log:
[change-namespace] fix namespace specifiers of template arguments.

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

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=285549&r1=285548&r2=285549&view=diff
==============================================================================
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Mon Oct 31 03:28:29 2016
@@ -272,13 +272,15 @@ void ChangeNamespaceTool::registerMatche
           allOf(IsInMovedNs, unless(cxxRecordDecl(unless(isDefinition())))))));
 
   // Match TypeLocs on the declaration. Carefully match only the outermost
-  // TypeLoc that's directly linked to the old class and don't handle nested
-  // name specifier locs.
+  // TypeLoc and template specialization arguments (which are not outermost)
+  // that are directly linked to types matching `DeclMatcher`. Nested name
+  // specifier locs are handled separately below.
   Finder->addMatcher(
       typeLoc(IsInMovedNs,
               loc(qualType(hasDeclaration(DeclMatcher.bind("from_decl")))),
-              unless(anyOf(hasParent(typeLoc(
-                               loc(qualType(hasDeclaration(DeclMatcher))))),
+              unless(anyOf(hasParent(typeLoc(loc(qualType(
+                               allOf(hasDeclaration(DeclMatcher),
+                                     unless(templateSpecializationType())))))),
                            hasParent(nestedNameSpecifierLoc()))),
               hasAncestor(decl().bind("dc")))
           .bind("type"),

Modified: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp?rev=285549&r1=285548&r2=285549&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp Mon Oct 31 03:28:29 2016
@@ -190,6 +190,47 @@ TEST_F(ChangeNamespaceTest, SimpleMoveWi
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, TypeLocInTemplateSpecialization) {
+  std::string Code = "namespace na {\n"
+                     "class A {};\n"
+                     "template <typename T>\n"
+                     "class B {};\n"
+                     "template <typename T1, typename T2>\n"
+                     "class Two {};\n"
+                     "namespace nc { class C {}; }\n"
+                     "} // na\n"
+                     "\n"
+                     "namespace na {\n"
+                     "namespace nb {\n"
+                     "void f() {\n"
+                     "  B<A> b;\n"
+                     "  B<nc::C> b_c;\n"
+                     "  Two<A, nc::C> two;\n"
+                     "}\n"
+                     "} // nb\n"
+                     "} // na\n";
+  std::string Expected = "namespace na {\n"
+                         "class A {};\n"
+                         "template <typename T>\n"
+                         "class B {};\n"
+                         "template <typename T1, typename T2>\n"
+                         "class Two {};\n"
+                         "namespace nc { class C {}; }\n"
+                         "} // na\n"
+                         "\n"
+                         "\n"
+                         "namespace x {\n"
+                         "namespace y {\n"
+                         "void f() {\n"
+                         "  na::B<na::A> b;\n"
+                         "  na::B<na::nc::C> b_c;\n"
+                         "  na::Two<na::A, na::nc::C> two;\n"
+                         "}\n"
+                         "} // namespace y\n"
+                         "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, LeaveForwardDeclarationBehind) {
   std::string Code = "namespace na {\n"
                      "namespace nb {\n"




More information about the cfe-commits mailing list