]> granicus.if.org Git - clang/commitdiff
Do not warn about whitespace between ??/ trigraph and newline in line comments if...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 18 Apr 2017 21:45:04 +0000 (21:45 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 18 Apr 2017 21:45:04 +0000 (21:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300609 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/Lexer.cpp
test/Lexer/cxx1z-trigraphs.cpp

index 5d0fe42defdde9277493a9dd22d7969dc44a4f27..dc911ef91b6caeb731cad8ddeb1f2a5ae9b27f15 100644 (file)
@@ -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);
     }
index 0ea2adbe1e034a3ce45f95bd196a813e477eafe8..08c45e51f833216171c1baa3e634dd34fbd840c2 100644 (file)
@@ -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 {{}}