<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Dec 29, 2015 at 6:28 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On Tue, Dec 29, 2015 at 3:23 PM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>On Tue, Dec 29, 2015 at 6:16 PM, Richard Smith via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div>On Tue, Dec 29, 2015 at 3:06 PM, Nico Weber via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: nico<br>
Date: Tue Dec 29 17:06:17 2015<br>
New Revision: 256595<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=256595&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=256595&view=rev</a><br>
Log:<br>
Emit a -Wmicrosoft warning when pasting /##/ into a comment token in MS mode.<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td<br>
    cfe/trunk/include/clang/Lex/TokenLexer.h<br>
    cfe/trunk/lib/Lex/PPLexerChange.cpp<br>
    cfe/trunk/lib/Lex/TokenLexer.cpp<br>
    cfe/trunk/test/Preprocessor/macro_paste_msextensions.c<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=256595&r1=256594&r2=256595&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=256595&r1=256594&r2=256595&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Dec 29 17:06:17 2015<br>
@@ -765,6 +765,7 @@ def MicrosoftCast : DiagGroup<"microsoft<br>
 def MicrosoftConstInit : DiagGroup<"microsoft-const-init">;<br>
 def MicrosoftVoidPseudoDtor : DiagGroup<"microsoft-void-pseudo-dtor">;<br>
 def MicrosoftAnonTag : DiagGroup<"microsoft-anon-tag">;<br>
+def MicrosoftCommentPaste : DiagGroup<"microsoft-comment-paste">;<br>
 // Aliases.<br>
 def : DiagGroup<"msvc-include", [MicrosoftInclude]>;<br>
                 // -Wmsvc-include = -Wmicrosoft-include<br>
@@ -778,7 +779,8 @@ def Microsoft : DiagGroup<"microsoft",<br>
      MicrosoftEnumValue, MicrosoftDefaultArgRedefinition, MicrosoftTemplate,<br>
      MicrosoftRedeclareStatic, MicrosoftEnumForwardReference, MicrosoftGoto,<br>
      MicrosoftFlexibleArray, MicrosoftExtraQualification, MicrosoftCast,<br>
-     MicrosoftConstInit, MicrosoftVoidPseudoDtor, MicrosoftAnonTag]>;<br>
+     MicrosoftConstInit, MicrosoftVoidPseudoDtor, MicrosoftAnonTag,<br>
+     MicrosoftCommentPaste]>;<br>
<br>
 def ObjCNonUnifiedException : DiagGroup<"objc-nonunified-exceptions">;<br>
<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=256595&r1=256594&r2=256595&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=256595&r1=256594&r2=256595&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Dec 29 17:06:17 2015<br>
@@ -59,6 +59,9 @@ def ext_dollar_in_identifier : Extension<br>
 def ext_charize_microsoft : Extension<<br>
   "charizing operator #@ is a Microsoft extension">,<br>
   InGroup<MicrosoftCharize>;<br>
+def ext_comment_paste_microsoft : Extension<<br>
+  "pasting two '/' tokens into a '//' comment token is a Microsoft extension">,<br></blockquote><div><br></div></div></div><div>It's not really technically correct to call this a token. Maybe drop the word "token" here?</div></div></div></div></blockquote><div><br></div></div></div><div>Thanks for the review! You mean only the second "token", not the first "tokens", right?</div></div></div></div></blockquote><div><br></div></div></div><div>Yes.</div></div></div></div></blockquote><div><br></div><div>Done in 256600.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>And FWIW I find this extension horrifying. =)</div><div><div class="h5"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+  InGroup<MicrosoftCommentPaste>;<br>
<br>
 def ext_token_used : Extension<"extension used">,<br>
   InGroup<DiagGroup<"language-extension-token">>;<br>
<br>
Modified: cfe/trunk/include/clang/Lex/TokenLexer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/TokenLexer.h?rev=256595&r1=256594&r2=256595&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/TokenLexer.h?rev=256595&r1=256594&r2=256595&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Lex/TokenLexer.h (original)<br>
+++ cfe/trunk/include/clang/Lex/TokenLexer.h Tue Dec 29 17:06:17 2015<br>
@@ -175,7 +175,7 @@ private:<br>
   /// macro, other active macros, and anything left on the current physical<br>
   /// source line of the expanded buffer.  Handle this by returning the<br>
   /// first token on the next line.<br>
-  void HandleMicrosoftCommentPaste(Token &Tok);<br>
+  void HandleMicrosoftCommentPaste(Token &Tok, SourceLocation OpLoc);<br>
<br>
   /// \brief If \p loc is a FileID and points inside the current macro<br>
   /// definition, returns the appropriate source location pointing at the<br>
<br>
Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=256595&r1=256594&r2=256595&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=256595&r1=256594&r2=256595&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)<br>
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Tue Dec 29 17:06:17 2015<br>
@@ -561,7 +561,6 @@ void Preprocessor::RemoveTopOfLexerStack<br>
 void Preprocessor::HandleMicrosoftCommentPaste(Token &Tok) {<br>
   assert(CurTokenLexer && !CurPPLexer &&<br>
          "Pasted comment can only be formed from macro");<br>
-<br>
   // We handle this by scanning for the closest real lexer, switching it to<br>
   // raw mode and preprocessor mode.  This will cause it to return \n as an<br>
   // explicit EOD token.<br>
<br>
Modified: cfe/trunk/lib/Lex/TokenLexer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=256595&r1=256594&r2=256595&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=256595&r1=256594&r2=256595&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)<br>
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Tue Dec 29 17:06:17 2015<br>
@@ -624,21 +624,22 @@ bool TokenLexer::PasteTokens(Token &Tok)<br>
       // error.  This occurs with "x ## +"  and other stuff.  Return with Tok<br>
       // unmodified and with RHS as the next token to lex.<br>
       if (isInvalid) {<br>
+        // Explicitly convert the token location to have proper expansion<br>
+        // information so that the user knows where it came from.<br>
+        SourceManager &SM = PP.getSourceManager();<br>
+        SourceLocation Loc =<br>
+          SM.createExpansionLoc(PasteOpLoc, ExpandLocStart, ExpandLocEnd, 2);<br>
+<br>
         // Test for the Microsoft extension of /##/ turning into // here on the<br>
         // error path.<br>
         if (PP.getLangOpts().MicrosoftExt && Tok.is(tok::slash) &&<br>
             RHS.is(tok::slash)) {<br>
-          HandleMicrosoftCommentPaste(Tok);<br>
+          HandleMicrosoftCommentPaste(Tok, Loc);<br>
           return true;<br>
         }<br>
<br>
         // Do not emit the error when preprocessing assembler code.<br>
         if (!PP.getLangOpts().AsmPreprocessor) {<br>
-          // Explicitly convert the token location to have proper expansion<br>
-          // information so that the user knows where it came from.<br>
-          SourceManager &SM = PP.getSourceManager();<br>
-          SourceLocation Loc =<br>
-            SM.createExpansionLoc(PasteOpLoc, ExpandLocStart, ExpandLocEnd, 2);<br>
           // If we're in microsoft extensions mode, downgrade this from a hard<br>
           // error to an extension that defaults to an error.  This allows<br>
           // disabling it.<br>
@@ -719,7 +720,9 @@ bool TokenLexer::isParsingPreprocessorDi<br>
 /// macro, other active macros, and anything left on the current physical<br>
 /// source line of the expanded buffer.  Handle this by returning the<br>
 /// first token on the next line.<br>
-void TokenLexer::HandleMicrosoftCommentPaste(Token &Tok) {<br>
+void TokenLexer::HandleMicrosoftCommentPaste(Token &Tok, SourceLocation OpLoc) {<br>
+  PP.Diag(OpLoc, diag::ext_comment_paste_microsoft);<br>
+<br>
   // We 'comment out' the rest of this macro by just ignoring the rest of the<br>
   // tokens that have not been lexed yet, if any.<br>
<br>
<br>
Modified: cfe/trunk/test/Preprocessor/macro_paste_msextensions.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_paste_msextensions.c?rev=256595&r1=256594&r2=256595&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_paste_msextensions.c?rev=256595&r1=256594&r2=256595&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Preprocessor/macro_paste_msextensions.c (original)<br>
+++ cfe/trunk/test/Preprocessor/macro_paste_msextensions.c Tue Dec 29 17:06:17 2015<br>
@@ -1,3 +1,4 @@<br>
+// RUN: %clang_cc1 -verify -fms-extensions -Wmicrosoft %s<br>
 // RUN: not %clang_cc1 -P -E -fms-extensions %s | FileCheck -strict-whitespace %s<br>
<br>
 // This horrible stuff should preprocess into (other than whitespace):<br>
@@ -10,6 +11,7 @@ int foo;<br>
 // CHECK: int foo;<br>
<br>
 #define comment /##/  dead tokens live here<br>
+// expected-warning@+1 {{pasting two '/' tokens}}<br>
 comment This is stupidity<br>
<br>
 int bar;<br>
@@ -18,6 +20,7 @@ int bar;<br>
<br>
 #define nested(x) int x comment cute little dead tokens...<br>
<br>
+// expected-warning@+1 {{pasting two '/' tokens}}<br>
 nested(baz)  rise of the dead tokens<br>
<br>
 ;<br>
@@ -29,13 +32,13 @@ nested(baz)  rise of the dead tokens<br>
 // rdar://8197149 - VC++ allows invalid token pastes: (##baz<br>
 #define foo(x) abc(x)<br>
 #define bar(y) foo(##baz(y))<br>
-bar(q)<br>
+bar(q) // expected-warning {{type specifier missing}} expected-error {{invalid preprocessing token}} expected-error {{parameter list without types}}<br>
<br>
 // CHECK: abc(baz(q))<br>
<br>
<br>
 #define str(x) #x<br>
 #define collapse_spaces(a, b, c, d) str(a ## - ## b ## - ## c ## d)<br>
-collapse_spaces(1a, b2, 3c, d4)<br>
+collapse_spaces(1a, b2, 3c, d4) // expected-error 4 {{invalid preprocessing token}} expected-error {{expected function body}}<br>
<br>
 // CHECK: "1a-b2-3cd4"<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div></div><br></div></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>