[clang-move] Support moving template class forward declarations.

llvm-svn: 284859
This commit is contained in:
Haojian Wu 2016-10-21 19:26:43 +00:00
parent 0109bf116f
commit 29c38f75a2
2 changed files with 10 additions and 2 deletions

View File

@ -406,8 +406,13 @@ void ClangMoveTool::run(const ast_matchers::MatchFinder::MatchResult &Result) {
} else if (const auto *FWD =
Result.Nodes.getNodeAs<clang::CXXRecordDecl>("fwd_decl")) {
// Skip all forwad declarations which appear after moved class declaration.
if (RemovedDecls.empty())
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<clang::NamespaceDecl>(
"anonymous_ns")) {
MovedDecls.emplace_back(ANS, &Result.Context->getSourceManager());

View File

@ -30,6 +30,7 @@ const char TestCCName[] = "foo.cc";
const char TestHeader[] = "namespace a {\n"
"class C1; // test\n"
"template <typename T> 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 <typename T> 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 <typename T> class C2;\n"
"namespace b {\n"
"// This is a Foo class\n"
"// which is used in\n"