From: Richard Smith Date: Tue, 18 Apr 2017 21:45:04 +0000 (+0000) Subject: Do not warn about whitespace between ??/ trigraph and newline in line comments if... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=961ed8002bce57c3ab6d138853983c629bf058e4;p=clang Do not warn about whitespace between ??/ trigraph and newline in line comments if trigraphs are disabled in the current language. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300609 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index 5d0fe42def..dc911ef91b 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -1171,6 +1171,8 @@ const char *Lexer::SkipEscapedNewLines(const char *P) { // If not a trigraph for escape, bail out. if (P[1] != '?' || P[2] != '/') return P; + // FIXME: Take LangOpts into account; the language might not + // support trigraphs. AfterEscape = P+3; } else { return P; @@ -2079,17 +2081,17 @@ bool Lexer::SkipLineComment(Token &Result, const char *CurPtr, HasSpace = true; } - if (*EscapePtr == '\\') // Escaped newline. + if (*EscapePtr == '\\') + // Escaped newline. CurPtr = EscapePtr; else if (EscapePtr[0] == '/' && EscapePtr[-1] == '?' && - EscapePtr[-2] == '?') // Trigraph-escaped newline. + EscapePtr[-2] == '?' && LangOpts.Trigraphs) + // Trigraph-escaped newline. CurPtr = EscapePtr-2; else break; // This is a newline, we're done. // If there was space between the backslash and newline, warn about it. - // FIXME: This warning is bogus if trigraphs are disabled and the line - // ended with '?' '?' '\\' '\n'. if (HasSpace && !isLexingRawMode()) Diag(EscapePtr, diag::backslash_newline_space); } diff --git a/test/Lexer/cxx1z-trigraphs.cpp b/test/Lexer/cxx1z-trigraphs.cpp index 0ea2adbe1e..08c45e51f8 100644 --- a/test/Lexer/cxx1z-trigraphs.cpp +++ b/test/Lexer/cxx1z-trigraphs.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -std=c++1z %s -verify -// RUN: %clang_cc1 -std=c++1z %s -ftrigraphs -fsyntax-only +// RUN: %clang_cc1 -std=c++1z %s -ftrigraphs -fsyntax-only 2>&1 | FileCheck --check-prefix=TRIGRAPHS %s ??= define foo ; // expected-error {{}} expected-warning {{trigraph ignored}} @@ -7,3 +7,8 @@ static_assert("??="[0] == '#', ""); // expected-error {{failed}} expected-warnin // ??/ error here; // expected-error {{}} + +// Note, there is intentionally trailing whitespace two lines below. +// TRIGRAPHS: :[[@LINE+1]]:{{.*}} backslash and newline separated by space +// ??/ +error here; // expected-error {{}}