[change-namespace] Fix a misplaced case when there is no trailing newline character at the end of the file.

Reviewers: ioeric

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D25226

llvm-svn: 283210
This commit is contained in:
Haojian Wu 2016-10-04 10:35:53 +00:00
parent 86b3a1e79b
commit ef8a6dcd09
2 changed files with 24 additions and 2 deletions

View File

@ -106,8 +106,9 @@ SourceLocation getStartOfNextLine(SourceLocation Loc, const SourceManager &SM,
// 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

View File

@ -513,6 +513,27 @@ TEST_F(ChangeNamespaceTest, DoNotFixStaticVariableOfClass) {
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