[clang-tools-extra] r298090 - [change-namespace] do not rename specialized template parameters.
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 17 07:05:39 PDT 2017
Author: ioeric
Date: Fri Mar 17 09:05:39 2017
New Revision: 298090
URL: http://llvm.org/viewvc/llvm-project?rev=298090&view=rev
Log:
[change-namespace] do not rename specialized template parameters.
Reviewers: hokein
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D31076
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=298090&r1=298089&r2=298090&view=diff
==============================================================================
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Fri Mar 17 09:05:39 2017
@@ -286,6 +286,15 @@ AST_MATCHER(EnumDecl, isScoped) {
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 @@ void ChangeNamespaceTool::fixTypeLoc(
// 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
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=298090&r1=298089&r2=298090&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp Fri Mar 17 09:05:39 2017
@@ -2006,6 +2006,52 @@ TEST_F(ChangeNamespaceTest, EnumInClass)
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
More information about the cfe-commits
mailing list