[clang] [Clang] Warn on backslash-newline-EOF (PR #97585)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 3 22:11:36 PDT 2024
================
@@ -3183,8 +3193,31 @@ bool Lexer::LexEndOfFile(Token &Result, const char *CurPtr) {
DiagID = diag::ext_no_newline_eof;
}
- Diag(BufferEnd, DiagID)
- << FixItHint::CreateInsertion(EndLoc, "\n");
+ if (LastNewline.empty()) {
+ Diag(BufferEnd, DiagID) << FixItHint::CreateInsertion(EndLoc, "\n");
+ } else {
+ // While the file physically ends in a newline, the previous
+ // line might have ended in a splice, so it would be deleted
+ const char *LastSpliceLocation = LastNewline.data();
+ while (LastSpliceLocation != BufferStart &&
+ isHorizontalWhitespace(*--LastSpliceLocation))
+ ;
----------------
Sirraide wrote:
This might just be me, but I personally typically prefer not to have `*--...` or `*...--` in the condition of a loop because it always gives me a massive headache when I think about what state everything is supposed to be in when the loop terminates. I *think* this might be correct, but I’m not 100% sure.
https://github.com/llvm/llvm-project/pull/97585
More information about the cfe-commits
mailing list