]> granicus.if.org Git - clang/commitdiff
Add another terrible VC++ compatibility hack: allow users to
authorChris Lattner <sabre@nondot.org>
Sat, 17 Jul 2010 16:24:30 +0000 (16:24 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 17 Jul 2010 16:24:30 +0000 (16:24 +0000)
allow invalid token pastes (when in -fms-extensions mode)
with -Wno-invalid-token-paste

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108624 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticLexKinds.td
lib/Lex/TokenLexer.cpp
test/Preprocessor/macro_paste_msextensions.c

index 21c93e7e8fa297b6c8ca60ae49c49a4815972705..41e9feff2de30d7847a647cf2edf189bea050200 100644 (file)
@@ -277,6 +277,9 @@ def err_too_few_args_in_macro_invoc : Error<
   "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<
index 56bb073e591998d1dea5964ab3d099acec0f7f41..55609492a7f1e44548312fd0ea09f26e98f517dc 100644 (file)
@@ -478,7 +478,7 @@ bool TokenLexer::PasteTokens(Token &Tok) {
           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 @@ bool TokenLexer::PasteTokens(Token &Tok) {
           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());
         }
 
index 71324064f7cd8e78ae88c8412165af77218edd9d..c5b42130b8ea1ee07c0f10841b5ab82b2da8de75 100644 (file)
@@ -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 @@ nested(baz)  rise of the dead tokens
 // 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))