================ @@ -3183,8 +3193,35 @@ 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 + StringRef WithoutLastNewline = + StringRef(BufferStart, LastNewline.data() - BufferStart); + while (!WithoutLastNewline.empty()) { + if (isHorizontalWhitespace(WithoutLastNewline.back())) { + WithoutLastNewline = WithoutLastNewline.drop_back(); + } else { + break; + } + } + + if (WithoutLastNewline.ends_with('\\') || + (LangOpts.Trigraphs && WithoutLastNewline.ends_with("??" + "/"))) { ---------------- MitalAshok wrote:
That gives a "warning: trigraph ignored [-Wtrigraphs]" warning when compiling this clang-format refuses to put concatenated string literals on the same line. I've changed this and added a comment, but let me know if this could be done in a cleaner way https://github.com/llvm/llvm-project/pull/97585 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits