diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index 01f56089d9491149fa5e3e3b45a86eb7357d0c50..a32b9025c1dd8ccc2428733811e892078ff38b6f 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -501,6 +501,8 @@ def ext_pp_bad_paste_ms : ExtWarn< InGroup<DiagGroup<"invalid-token-paste">>; def err_pp_operator_used_as_macro_name : Error< "C++ operator %0 (aka %1) used as a macro name">; +def ext_pp_operator_used_as_macro_name : Extension< + "C++ operator %0 (aka %1) used as a macro name">, InGroup<Microsoft>; def err_pp_illegal_floating_literal : Error< "floating point literal in preprocessor expression">; def err_pp_line_requires_integer : Error< diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 46e8f07c510a77f367c94900f490b9ed83375732..a8dde086baf24382c2886de997478d7d5c674916 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -145,11 +145,12 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, char isDefineUndef) { if (!II->isCPlusPlusOperatorKeyword()) return Diag(MacroNameTok, diag::err_pp_macro_not_identifier); - if (!getLangOpts().MSVCCompat) - // C++ 2.5p2: Alternative tokens behave the same as its primary token - // except for their spellings. - Diag(MacroNameTok, diag::err_pp_operator_used_as_macro_name) - << II << MacroNameTok.getKind(); + // C++ 2.5p2: Alternative tokens behave the same as its primary token + // except for their spellings. + Diag(MacroNameTok, getLangOpts().MicrosoftExt + ? diag::ext_pp_operator_used_as_macro_name + : diag::err_pp_operator_used_as_macro_name) + << II << MacroNameTok.getKind(); // Allow #defining |and| and friends for Microsoft compatibility or // recovery when legacy C headers are included in C++. diff --git a/test/Parser/MicrosoftExtensions.cpp b/test/Parser/MicrosoftExtensions.cpp index 5f3c2a26fc03e4b8d37593c3b1f184a9e3ec12a2..72d6c2ed58c4d479944c753cc092342b8ddc58b4 100644 --- a/test/Parser/MicrosoftExtensions.cpp +++ b/test/Parser/MicrosoftExtensions.cpp @@ -426,3 +426,6 @@ void TestProperty() { sp.V11++; ++sp.V11; } + +//expected-warning@+1 {{C++ operator 'and' (aka '&&') used as a macro name}} +#define and foo diff --git a/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp b/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp index dcf6908c329e232bb6edc9300de9193fb5aa7f1e..8e1351e3472861651e12ca2161ba87010125e24a 100644 --- a/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp +++ b/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 %s -E -fms-compatibility +// RUN: %clang_cc1 %s -E -verify -fms-extensions +// expected-no-diagnostics bool f() { // Check that operators still work before redefining them.