[clang-tools-extra] r293897 - [change-namespace] check using shadow decl correctly when shortening namespace specifiers.
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 2 07:29:54 PST 2017
Author: ioeric
Date: Thu Feb 2 09:29:54 2017
New Revision: 293897
URL: http://llvm.org/viewvc/llvm-project?rev=293897&view=rev
Log:
[change-namespace] check using shadow decl correctly when shortening namespace specifiers.
Summary:
This fixes mismatch between template decls and template specialization decls.
Also added a few more test cases.
Reviewers: bkramer
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D29447
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=293897&r1=293896&r2=293897&view=diff
==============================================================================
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Thu Feb 2 09:29:54 2017
@@ -761,7 +761,8 @@ void ChangeNamespaceTool::replaceQualifi
if (isDeclVisibleAtLocation(*Result.SourceManager, Using, DeclCtx, Start)) {
for (const auto *UsingShadow : Using->shadows()) {
const auto *TargetDecl = UsingShadow->getTargetDecl();
- if (TargetDecl == FromDecl) {
+ if (TargetDecl->getQualifiedNameAsString() ==
+ FromDecl->getQualifiedNameAsString()) {
ReplaceName = FromDecl->getNameAsString();
Matched = true;
break;
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=293897&r1=293896&r2=293897&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp Thu Feb 2 09:29:54 2017
@@ -1255,7 +1255,7 @@ TEST_F(ChangeNamespaceTest, UsingDeclInM
EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
}
-TEST_F(ChangeNamespaceTest, UsingDeclInTheParentOfOldNamespace) {
+TEST_F(ChangeNamespaceTest, UsingShadowDeclInTheParentOfOldNamespace) {
OldNamespace = "nb::nc";
NewNamespace = "nb::nd";
std::string Code = "namespace na { class A {}; }\n"
@@ -1277,6 +1277,74 @@ TEST_F(ChangeNamespaceTest, UsingDeclInT
EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
}
+TEST_F(ChangeNamespaceTest, UsingShadowDeclInOldNamespace) {
+ OldNamespace = "nb";
+ NewNamespace = "nc";
+ std::string Code = "namespace na { class A {}; }\n"
+ "namespace nb {\n"
+ "using na::A;\n"
+ "void d() { A a; }\n"
+ "struct X { A a; };\n"
+ "} // nb\n";
+
+ std::string Expected = "namespace na { class A {}; }\n"
+ "\n"
+ "namespace nc {\n"
+ "using ::na::A;\n"
+ "void d() { A a; }\n"
+ "struct X { A a; };\n"
+ "} // namespace nc\n";
+ EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, UsingShadowDeclOfTemplateClass) {
+ OldNamespace = "nb";
+ NewNamespace = "nc";
+ std::string Code = "namespace na {\n"
+ "template <typename T>\n"
+ "class A { T t; };\n"
+ "} // namespace na\n"
+ "namespace nb {\n"
+ "using na::A;\n"
+ "void d() { A<int> a; }\n"
+ "} // nb\n";
+
+ std::string Expected = "namespace na {\n"
+ "template <typename T>\n"
+ "class A { T t; };\n"
+ "} // namespace na\n"
+ "\n"
+ "namespace nc {\n"
+ "using ::na::A;\n"
+ "void d() { A<int> a; }\n"
+ "} // namespace nc\n";
+ EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, UsingShadowDeclOfTemplateFunction) {
+ OldNamespace = "nb";
+ NewNamespace = "nc";
+ std::string Code = "namespace na {\n"
+ "template <typename T>\n"
+ "void f() { T t; };\n"
+ "} // namespace na\n"
+ "namespace nb {\n"
+ "using na::f;\n"
+ "void d() { f<int>(); }\n"
+ "} // nb\n";
+
+ std::string Expected = "namespace na {\n"
+ "template <typename T>\n"
+ "void f() { T t; };\n"
+ "} // namespace na\n"
+ "\n"
+ "namespace nc {\n"
+ "using ::na::f;\n"
+ "void d() { f<int>(); }\n"
+ "} // namespace nc\n";
+ EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
TEST_F(ChangeNamespaceTest, UsingAliasDecl) {
std::string Code =
"namespace nx { namespace ny { class X {}; } }\n"
More information about the cfe-commits
mailing list