Index: clang-move/ClangMove.cpp =================================================================== --- clang-move/ClangMove.cpp +++ clang-move/ClangMove.cpp @@ -523,6 +523,7 @@ auto AllDeclsInHeader = namedDecl( unless(ForwardClassDecls), unless(namespaceDecl()), unless(usingDirectiveDecl()), // using namespace decl. + notInMacro(), InOldHeader, hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl()))), hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl())))); @@ -905,10 +906,9 @@ if (RemovedDecls.empty()) return; - // Ignore symbols that are not supported (e.g. typedef and enum) when - // checking if there is unremoved symbol in old header. This makes sure that - // we always move old files to new files when all symbols produced from - // dump_decls are moved. + // Ignore symbols that are not supported when checking if there is unremoved + // symbol in old header. This makes sure that we always move old files to new + // files when all symbols produced from dump_decls are moved. auto IsSupportedKind = [](const clang::NamedDecl *Decl) { switch (Decl->getKind()) { case Decl::Kind::Function: Index: unittests/clang-move/ClangMoveTests.cpp =================================================================== --- unittests/clang-move/ClangMoveTests.cpp +++ unittests/clang-move/ClangMoveTests.cpp @@ -391,6 +391,26 @@ } } +TEST(ClangMove, IgnoreMacroSymbolsAndMoveAll) { + const char TestCode[] = "#include \"foo.h\""; + std::vector TestHeaders = { + "#define DEFINE_Foo int Foo = 1;\nDEFINE_Foo;\nclass Bar {};\n", + "#define DEFINE(x) int var_##x = 1;\nDEFINE(foo);\nclass Bar {};\n", + }; + move::MoveDefinitionSpec Spec; + Spec.Names.push_back("Bar"); + Spec.OldHeader = "foo.h"; + Spec.OldCC = "foo.cc"; + Spec.NewHeader = "new_foo.h"; + Spec.NewCC = "new_foo.cc"; + + for (const auto& Header : TestHeaders) { + auto Results = runClangMoveOnCode(Spec, Header.c_str(), TestCode); + EXPECT_EQ("", Results[Spec.OldHeader]); + EXPECT_EQ(Header, Results[Spec.NewHeader]); + } +} + TEST(ClangMove, MacroInFunction) { const char TestHeader[] = "#define INT int\n" "class A {\npublic:\n int f();\n};\n" @@ -570,7 +590,9 @@ "extern int kGlobalInt;\n" "extern const char* const kGlobalStr;\n" "} // namespace b\n" - "} // namespace a\n"; + "} // namespace a\n" + "#define DEFINE_FOO class Foo {};\n" + "DEFINE_FOO\n"; const char TestCode[] = "#include \"foo.h\"\n"; move::MoveDefinitionSpec Spec; Spec.Names.push_back("B");