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

Alp Toker alp at nuanti.com
Sat May 31 09:32:22 PDT 2014


Author: alp
Date: Sat May 31 11:32:22 2014
New Revision: 209978

URL: http://llvm.org/viewvc/llvm-project?rev=209978&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/test/Parser/MicrosoftExtensions.cpp
    cfe/trunk/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=209978&r1=209977&r2=209978&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Sat May 31 11:32:22 2014
@@ -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<

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=209978&r1=209977&r2=209978&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sat May 31 11:32:22 2014
@@ -145,11 +145,12 @@ bool Preprocessor::CheckMacroName(Token
     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++.

Modified: cfe/trunk/test/Parser/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.cpp?rev=209978&r1=209977&r2=209978&view=diff
==============================================================================
--- cfe/trunk/test/Parser/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp Sat May 31 11:32:22 2014
@@ -426,3 +426,6 @@ void TestProperty() {
   sp.V11++;
   ++sp.V11;
 }
+
+//expected-warning at +1 {{C++ operator 'and' (aka '&&') used as a macro name}}
+#define and foo

Modified: cfe/trunk/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp?rev=209978&r1=209977&r2=209978&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp (original)
+++ cfe/trunk/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp Sat May 31 11:32:22 2014
@@ -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.





More information about the cfe-commits mailing list