From 29c38f75a2c86a99655b68c4aa8879b0f2ea2d9d Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 21 Oct 2016 19:26:43 +0000 Subject: [PATCH] [clang-move] Support moving template class forward declarations. llvm-svn: 284859 --- clang-tools-extra/clang-move/ClangMove.cpp | 9 +++++++-- clang-tools-extra/unittests/clang-move/ClangMoveTests.cpp | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-move/ClangMove.cpp b/clang-tools-extra/clang-move/ClangMove.cpp index 62356d2..dea41b2 100644 --- a/clang-tools-extra/clang-move/ClangMove.cpp +++ b/clang-tools-extra/clang-move/ClangMove.cpp @@ -406,8 +406,13 @@ void ClangMoveTool::run(const ast_matchers::MatchFinder::MatchResult &Result) { } else if (const auto *FWD = Result.Nodes.getNodeAs("fwd_decl")) { // Skip all forwad declarations which appear after moved class declaration. - if (RemovedDecls.empty()) - MovedDecls.emplace_back(FWD, &Result.Context->getSourceManager()); + if (RemovedDecls.empty()) { + if (const auto *DCT = FWD->getDescribedClassTemplate()) { + MovedDecls.emplace_back(DCT, &Result.Context->getSourceManager()); + } else { + MovedDecls.emplace_back(FWD, &Result.Context->getSourceManager()); + } + } } else if (const auto *ANS = Result.Nodes.getNodeAs( "anonymous_ns")) { MovedDecls.emplace_back(ANS, &Result.Context->getSourceManager()); diff --git a/clang-tools-extra/unittests/clang-move/ClangMoveTests.cpp b/clang-tools-extra/unittests/clang-move/ClangMoveTests.cpp index b4b4ae9..572a0f0 100644 --- a/clang-tools-extra/unittests/clang-move/ClangMoveTests.cpp +++ b/clang-tools-extra/unittests/clang-move/ClangMoveTests.cpp @@ -30,6 +30,7 @@ const char TestCCName[] = "foo.cc"; const char TestHeader[] = "namespace a {\n" "class C1; // test\n" + "template class C2;\n" "namespace b {\n" "// This is a Foo class\n" "// which is used in\n" @@ -87,6 +88,7 @@ const char TestCC[] = "#include \"foo.h\"\n" const char ExpectedTestHeader[] = "namespace a {\n" "class C1; // test\n" + "template class C2;\n" "namespace b {\n" "\n" "class Foo2 {\n" @@ -127,6 +129,7 @@ const char ExpectedNewHeader[] = "#ifndef NEW_FOO_H\n" "#define NEW_FOO_H\n" "namespace a {\n" "class C1; // test\n" + "template class C2;\n" "namespace b {\n" "// This is a Foo class\n" "// which is used in\n" -- 2.7.4