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 @@ -219,7 +219,8 @@ getLocForEndOfDecl(const clang::Decl *D, const LangOptions &LangOpts = clang::LangOptions()) { const auto &SM = D->getASTContext().getSourceManager(); - std::pair LocInfo = SM.getDecomposedLoc(D->getLocEnd()); + auto EndExpansionLoc = SM.getExpansionLoc(D->getLocEnd()); + std::pair LocInfo = SM.getDecomposedLoc(EndExpansionLoc); // Try to load the file buffer. bool InvalidTemp = false; llvm::StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp); @@ -235,7 +236,7 @@ // FIXME: this is a bit hacky to get ReadToEndOfLine work. Lex.setParsingPreprocessorDirective(true); Lex.ReadToEndOfLine(&Line); - SourceLocation EndLoc = D->getLocEnd().getLocWithOffset(Line.size()); + SourceLocation EndLoc = EndExpansionLoc.getLocWithOffset(Line.size()); // If we already reach EOF, just return the EOF SourceLocation; // otherwise, move 1 offset ahead to include the trailing newline character // '\n'. 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 @@ -386,6 +386,24 @@ EXPECT_EQ(ExpectedNewCode, Results[Spec.NewCC]); } +TEST(ClangMove, DefinitionInMacro) { + const char TestHeader[] = "#define DEF(CLASS) void CLASS##_::f() {}\n" + "class A_ {\nvoid f();\n};\n" + "class B {};\n"; + const char TestCode[] = "#include \"foo.h\"\n" + "DEF(A)\n"; + const char ExpectedNewCode[] = "#include \"new_foo.h\"\n\n" + "DEF(A)\n"; + move::MoveDefinitionSpec Spec; + Spec.Names.push_back("A_"); + Spec.OldHeader = "foo.h"; + Spec.OldCC = "foo.cc"; + Spec.NewHeader = "new_foo.h"; + Spec.NewCC = "new_foo.cc"; + auto Results = runClangMoveOnCode(Spec, TestHeader, TestCode); + EXPECT_EQ(ExpectedNewCode, Results[Spec.NewCC]); +} + TEST(ClangMove, WellFormattedCode) { const std::string CommonHeader = "namespace a {\n"