This revision was automatically updated to reflect the committed changes. Closed by commit rL283210: [change-namespace] Fix a misplaced case when there is no trailing newline… (authored by hokein).
Changed prior to commit: https://reviews.llvm.org/D25226?vs=73420&id=73447#toc Repository: rL LLVM https://reviews.llvm.org/D25226 Files: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp Index: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp +++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp @@ -513,6 +513,27 @@ EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code)); } +TEST_F(ChangeNamespaceTest, NoMisplaceAtEOF) { + std::string Code = "namespace na {\n" + "namespace nb {\n" + "class A;\n" + "class B {};\n" + "}" + "}"; + std::string Expected = "namespace na {\n" + "namespace nb {\n" + "class A;\n" + "}\n" + "}\n" + "namespace x {\n" + "namespace y {\n" + "\n" + "class B {};\n" + "} // namespace y\n" + "} // namespace x\n"; + EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code)); +} + } // anonymous namespace } // namespace change_namespace } // namespace clang Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp =================================================================== --- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp +++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp @@ -106,8 +106,9 @@ // FIXME: this is a bit hacky to get ReadToEndOfLine work. Lex.setParsingPreprocessorDirective(true); Lex.ReadToEndOfLine(&Line); - // FIXME: should not +1 at EOF. - return Loc.getLocWithOffset(Line.size() + 1); + auto End = Loc.getLocWithOffset(Line.size()); + return SM.getLocForEndOfFile(LocInfo.first) == End ? End + : End.getLocWithOffset(1); } // Returns `R` with new range that refers to code after `Replaces` being
Index: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp +++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp @@ -513,6 +513,27 @@ EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code)); } +TEST_F(ChangeNamespaceTest, NoMisplaceAtEOF) { + std::string Code = "namespace na {\n" + "namespace nb {\n" + "class A;\n" + "class B {};\n" + "}" + "}"; + std::string Expected = "namespace na {\n" + "namespace nb {\n" + "class A;\n" + "}\n" + "}\n" + "namespace x {\n" + "namespace y {\n" + "\n" + "class B {};\n" + "} // namespace y\n" + "} // namespace x\n"; + EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code)); +} + } // anonymous namespace } // namespace change_namespace } // namespace clang Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp =================================================================== --- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp +++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp @@ -106,8 +106,9 @@ // FIXME: this is a bit hacky to get ReadToEndOfLine work. Lex.setParsingPreprocessorDirective(true); Lex.ReadToEndOfLine(&Line); - // FIXME: should not +1 at EOF. - return Loc.getLocWithOffset(Line.size() + 1); + auto End = Loc.getLocWithOffset(Line.size()); + return SM.getLocForEndOfFile(LocInfo.first) == End ? End + : End.getLocWithOffset(1); } // Returns `R` with new range that refers to code after `Replaces` being
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits