Skip to content
Snippets Groups Projects
Commit 5c0a1a44 authored by Alp Toker's avatar Alp Toker
Browse files

Preprocessor: make C++ operator names as macro identifiers a compatible extension

With recent changes, this is now a compatible language extension and can be
safely enabled with -ms-extensions instead of requiring the full
-ms-compatibility MSVC drop-in mode. As such we can now also emit an extension
warning under -Wmicrosoft to help users port their code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209978 91177308-0d34-0410-b5e6-96231b3b80d8
parent 733637bb
No related branches found
No related tags found
No related merge requests found
......@@ -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<
......
......@@ -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++.
......
......@@ -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
// 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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment