[clang] [Clang] Warn on backslash-newline-EOF (PR #97585)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 11 07:26:42 PDT 2024
================
@@ -3165,7 +3165,17 @@ bool Lexer::LexEndOfFile(Token &Result, const char *CurPtr) {
// C99 5.1.1.2p2: If the file is non-empty and didn't end in a newline, issue
// a pedwarn.
- if (CurPtr != BufferStart && (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')) {
+ if (CurPtr != BufferStart) {
+ StringRef LastNewline;
+ if (CurPtr[-1] == '\r' || CurPtr[-1] == '\n') {
+ LastNewline = StringRef(CurPtr - 1, 1);
+ if (CurPtr - 1 != BufferStart && CurPtr[-2] != CurPtr[-1] &&
+ (CurPtr[-2] == '\r' || CurPtr[-2] == '\n')) {
+ // \r\n or \n\r is one newline
----------------
AaronBallman wrote:
Why is `\n\r` one newline as opposed to a mixed set of two newlines? `/r/n` makes sense to me as that's the Windows line ending.
https://github.com/llvm/llvm-project/pull/97585
More information about the cfe-commits
mailing list