Lexer: Issue -Wbackslash-newline-escape for line comments

The warning for backslash and newline separated by whitespace was missed in
this code path.

backslash<whitespace><newline> is handled differently from compiler to compiler
so it's important to warn consistently where there's ambiguity.

Matches similar handling of block comments and non-comment lines.

llvm-svn: 197331
This commit is contained in:
Alp Toker 2013-12-14 23:32:31 +00:00
parent 099b0d3741
commit 6de6da603e
2 changed files with 9 additions and 1 deletions

View File

@ -2023,8 +2023,11 @@ bool Lexer::SkipLineComment(Token &Result, const char *CurPtr,
if (C != 0) {
// We found a newline, see if it's escaped.
const char *EscapePtr = CurPtr-1;
while (isHorizontalWhitespace(*EscapePtr)) // Skip whitespace.
bool HasSpace = false;
while (isHorizontalWhitespace(*EscapePtr)) { // Skip whitespace.
--EscapePtr;
HasSpace = true;
}
if (*EscapePtr == '\\') // Escaped newline.
CurPtr = EscapePtr;
@ -2033,6 +2036,10 @@ bool Lexer::SkipLineComment(Token &Result, const char *CurPtr,
CurPtr = EscapePtr-2;
else
break; // This is a newline, we're done.
// If there was space between the backslash and newline, warn about it.
if (HasSpace && !isLexingRawMode())
Diag(EscapePtr, diag::backslash_newline_space);
}
// Otherwise, this is a hard case. Fall back on getAndAdvanceChar to

View File

@ -11,3 +11,4 @@
// Trailing whitespace!
//\
#error quux
// expected-warning@-2 {{backslash and newline separated by space}}