[cfe-commits] r108624 - in /cfe/trunk: include/clang/Basic/DiagnosticLexKinds.td lib/Lex/TokenLexer.cpp test/Preprocessor/macro_paste_msextensions.c

Chris Lattner sabre at nondot.org
Sat Jul 17 09:24:30 PDT 2010


Author: lattner
Date: Sat Jul 17 11:24:30 2010
New Revision: 108624

URL: http://llvm.org/viewvc/llvm-project?rev=108624&view=rev
Log:
Add another terrible VC++ compatibility hack: allow users to
allow invalid token pastes (when in -fms-extensions mode)
with -Wno-invalid-token-paste

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
    cfe/trunk/lib/Lex/TokenLexer.cpp
    cfe/trunk/test/Preprocessor/macro_paste_msextensions.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=108624&r1=108623&r2=108624&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Sat Jul 17 11:24:30 2010
@@ -277,6 +277,9 @@
   "too few arguments provided to function-like macro invocation">;
 def err_pp_bad_paste : Error<
   "pasting formed '%0', an invalid preprocessing token">;
+def err_pp_bad_paste_ms : Warning<
+  "pasting formed '%0', an invalid preprocessing token">, DefaultError,
+  InGroup<DiagGroup<"invalid-token-paste">>;
 def err_pp_operator_used_as_macro_name : Error<
   "C++ operator '%0' cannot be used as a macro name">;
 def err_pp_illegal_floating_literal : Error<

Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=108624&r1=108623&r2=108624&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Sat Jul 17 11:24:30 2010
@@ -478,7 +478,7 @@
           return true;
         }
 
-        // Do not emit the warning when preprocessing assembler code.
+        // Do not emit the error when preprocessing assembler code.
         if (!PP.getLangOptions().AsmPreprocessor) {
           // Explicitly convert the token location to have proper instantiation
           // information so that the user knows where it came from.
@@ -486,7 +486,12 @@
           SourceLocation Loc =
             SM.createInstantiationLoc(PasteOpLoc, InstantiateLocStart,
                                       InstantiateLocEnd, 2);
-          PP.Diag(Loc, diag::err_pp_bad_paste)
+          // If we're in microsoft extensions mode, downgrade this from a hard
+          // error to a warning that defaults to an error.  This allows
+          // disabling it.
+          PP.Diag(Loc,
+                  PP.getLangOptions().Microsoft ? diag::err_pp_bad_paste_ms 
+                                                : diag::err_pp_bad_paste)
             << std::string(Buffer.begin(), Buffer.end());
         }
 

Modified: cfe/trunk/test/Preprocessor/macro_paste_msextensions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_paste_msextensions.c?rev=108624&r1=108623&r2=108624&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/macro_paste_msextensions.c (original)
+++ cfe/trunk/test/Preprocessor/macro_paste_msextensions.c Sat Jul 17 11:24:30 2010
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -P -E -fms-extensions %s | FileCheck -strict-whitespace %s
+
 // This horrible stuff should preprocess into (other than whitespace):
 //   int foo;
 //   int bar;
@@ -24,3 +25,10 @@
 // CHECK: int baz
 // CHECK: ;
 
+
+// rdar://8197149 - VC++ allows invalid token pastes: (##baz
+#define foo(x) abc(x)
+#define bar(y) foo(##baz(y))
+bar(q)
+
+// CHECK: abc(baz(q))





More information about the cfe-commits mailing list