Index: clang-tools-extra/trunk/clang-move/ClangMove.cpp =================================================================== --- clang-tools-extra/trunk/clang-move/ClangMove.cpp +++ clang-tools-extra/trunk/clang-move/ClangMove.cpp @@ -504,8 +504,11 @@ isExpansionInFile(makeAbsolutePath(Context->Spec.OldHeader)); auto InOldCC = isExpansionInFile(makeAbsolutePath(Context->Spec.OldCC)); auto InOldFiles = anyOf(InOldHeader, InOldCC); - auto ForwardDecls = - cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition()))); + auto classTemplateForwardDecls = + classTemplateDecl(unless(has(cxxRecordDecl(isDefinition())))); + auto ForwardClassDecls = namedDecl( + anyOf(cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition()))), + classTemplateForwardDecls)); auto TopLevelDecl = hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl())); @@ -518,9 +521,8 @@ // We consider declarations inside a class belongs to the class. So these // declarations will be ignored. auto AllDeclsInHeader = namedDecl( - unless(ForwardDecls), unless(namespaceDecl()), - unless(usingDirectiveDecl()), // using namespace decl. - unless(classTemplateDecl(has(ForwardDecls))), // template forward decl. + unless(ForwardClassDecls), unless(namespaceDecl()), + unless(usingDirectiveDecl()), // using namespace decl. InOldHeader, hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl()))), hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl())))); @@ -531,7 +533,7 @@ return; // Match forward declarations in old header. - Finder->addMatcher(namedDecl(ForwardDecls, InOldHeader).bind("fwd_decl"), + Finder->addMatcher(namedDecl(ForwardClassDecls, InOldHeader).bind("fwd_decl"), this); //============================================================================ Index: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp +++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp @@ -531,6 +531,7 @@ "void f2();\n" "} // namespace a\n" "\n" + "class ForwardClass;\n" "namespace a {\n" "namespace b {\n" "class Move1 { public : void f(); };\n" @@ -538,6 +539,7 @@ "enum E1 { Green };\n" "enum class E2 { Red };\n" "typedef int Int2;\n" + "typedef A A_d;" "using Int = int;\n" "extern int kGlobalInt;\n" "extern const char* const kGlobalStr;\n" @@ -552,11 +554,20 @@ Spec.NewCC = "new_foo.cc"; DeclarationReporter Reporter; std::set ExpectedDeclarations = { - {"A", "Class"}, {"B", "Class"}, {"a::Move1", "Class"}, - {"a::f1", "Function"}, {"a::f2", "Function"}, {"a::b::Move1", "Class"}, - {"a::b::f", "Function"}, {"a::b::E1", "Enum"}, {"a::b::E2", "Enum"}, - {"a::b::Int2", "TypeAlias"}, {"a::b::Int", "TypeAlias"}, - {"a::b::kGlobalInt", "Variable"}, {"a::b::kGlobalStr", "Variable"}}; + {"A", "Class"}, + {"B", "Class"}, + {"a::Move1", "Class"}, + {"a::f1", "Function"}, + {"a::f2", "Function"}, + {"a::b::Move1", "Class"}, + {"a::b::f", "Function"}, + {"a::b::E1", "Enum"}, + {"a::b::E2", "Enum"}, + {"a::b::Int2", "TypeAlias"}, + {"a::b::A_d", "TypeAlias"}, + {"a::b::Int", "TypeAlias"}, + {"a::b::kGlobalInt", "Variable"}, + {"a::b::kGlobalStr", "Variable"}}; runClangMoveOnCode(Spec, TestHeader, TestCode, &Reporter); std::set Results; for (const auto& DelPair : Reporter.getDeclarationList())