From: Chris Lattner Date: Sat, 17 Jul 2010 16:24:30 +0000 (+0000) Subject: Add another terrible VC++ compatibility hack: allow users to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=920bf45bd739334c25633ec9a29d903cab50be23;p=clang Add another terrible VC++ compatibility hack: allow users to 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 --- diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index 21c93e7e8f..41e9feff2d 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -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>; 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< diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp index 56bb073e59..55609492a7 100644 --- a/lib/Lex/TokenLexer.cpp +++ b/lib/Lex/TokenLexer.cpp @@ -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()); } diff --git a/test/Preprocessor/macro_paste_msextensions.c b/test/Preprocessor/macro_paste_msextensions.c index 71324064f7..c5b42130b8 100644 --- a/test/Preprocessor/macro_paste_msextensions.c +++ b/test/Preprocessor/macro_paste_msextensions.c @@ -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))