[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 06:08:17 PDT 2017
ioeric created this revision.
https://reviews.llvm.org/D31076
Files:
change-namespace/ChangeNamespace.cpp
unittests/change-namespace/ChangeNamespaceTests.cpp
Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===================================================================
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ 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
Index: change-namespace/ChangeNamespace.cpp
===================================================================
--- change-namespace/ChangeNamespace.cpp
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31076.92135.patch
Type: text/x-patch
Size: 3204 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170317/eb8b8494/attachment.bin>
More information about the cfe-commits
mailing list