r303798 - For Microsoft compatibility, set fno_operator_names

Blower, Melanie via cfe-commits cfe-commits at lists.llvm.org
Wed May 24 13:01:04 PDT 2017

Thanks for the feedback, working on it…

From: Keane, Erich
Sent: Wednesday, May 24, 2017 3:47 PM
To: Nico Weber <thakis at chromium.org>; Blower, Melanie <melanie.blower at intel.com>
Cc: cfe-commits <cfe-commits at lists.llvm.org>; rnk <rnk at chromium.org>
Subject: RE: r303798 - For Microsoft compatibility, set fno_operator_names

Adding Melanie, the author of the patch.

From: thakis at google.com<mailto:thakis at google.com> [mailto:thakis at google.com] On Behalf Of Nico Weber
Sent: Wednesday, May 24, 2017 12:43 PM
To: Keane, Erich <erich.keane at intel.com<mailto:erich.keane at intel.com>>
Cc: cfe-commits <cfe-commits at lists.llvm.org<mailto:cfe-commits at lists.llvm.org>>; rnk <rnk at chromium.org<mailto:rnk at chromium.org>>
Subject: Re: r303798 - For Microsoft compatibility, set fno_operator_names

Reviewed here: https://reviews.llvm.org/D33505

Still, please make this warn.

On Wed, May 24, 2017 at 3:42 PM, Nico Weber <thakis at google.com<mailto:thakis at google.com>> wrote:
Was this reviewed somewhere?

Please make it so that this emits a warning. We want clang-cl to warn on invalid code (and in system headers warnings are suppressed).

On Wed, May 24, 2017 at 3:31 PM, Erich Keane via cfe-commits <cfe-commits at lists.llvm.org<mailto:cfe-commits at lists.llvm.org>> wrote:
Author: erichkeane
Date: Wed May 24 14:31:19 2017
New Revision: 303798

URL: http://llvm.org/viewvc/llvm-project?rev=303798&view=rev
For Microsoft compatibility, set fno_operator_names

There's a Microsoft header in the Windows SDK which won't
compile with clang because it uses an operator name (and)
as a field name. This patch allows that file to compile by
setting the option which disables operator names.
The header which doesn't compile <Query.h> C:/Program Files (x86)/
Windows Kits/10/include/10.0.14393.0/um\Query.h:259:40:
error: expected member name or ';' after declaration specifiers

  /* [case()] */ NODERESTRICTION or;
                   ~~~~~~~~~~~~~~~ ^

                   1 error generated.

Contributed for Melanie Blower

Differential Revision:https://reviews.llvm.org/D33505


Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=303798&r1=303797&r2=303798&view=diff
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed May 24 14:31:19 2017
@@ -1882,7 +1882,7 @@ static void ParseLangArgs(LangOptions &O
   Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,

-  if (Args.hasArg(OPT_fno_operator_names))
+  if (Args.hasArg(OPT_fno_operator_names) || Args.hasArg(OPT_fms_compatibility))
     Opts.CXXOperatorNames = 0;

   if (Args.hasArg(OPT_fcuda_is_device))

Modified: cfe/trunk/test/Parser/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.cpp?rev=303798&r1=303797&r2=303798&view=diff
--- cfe/trunk/test/Parser/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp Wed May 24 14:31:19 2017
@@ -261,9 +261,8 @@ int __identifier(else} = __identifier(fo
 #define identifier_weird(x) __identifier(x
 int k = identifier_weird(if)); // expected-error {{use of undeclared identifier 'if'}}

-// This is a bit weird, but the alternative tokens aren't keywords, and this
-// behavior matches MSVC. FIXME: Consider supporting this anyway.
-extern int __identifier(and) r; // expected-error {{cannot convert '&&' token to an identifier}}
+// 'and' is not an operator name with Microsoft compatibility.
+extern int __identifier(and) r; // expected-error {{expected ';' after top level declarator}}

 void f() {
   __identifier(() // expected-error {{cannot convert '(' token to an identifier}}
@@ -355,7 +354,6 @@ void TestProperty() {

-//expected-warning at +1 {{C++ operator 'and' (aka '&&') used as a macro name}}
 #define and foo

 struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) IUnknown {};

Modified: cfe/trunk/test/Preprocessor/cxx_oper_keyword.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/cxx_oper_keyword.cpp?rev=303798&r1=303797&r2=303798&view=diff
--- cfe/trunk/test/Preprocessor/cxx_oper_keyword.cpp (original)
+++ cfe/trunk/test/Preprocessor/cxx_oper_keyword.cpp Wed May 24 14:31:19 2017
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -E -verify -DOPERATOR_NAMES
 // RUN: %clang_cc1 %s -E -verify -fno-operator-names
+// RUN: %clang_cc1 %s    -verify -DTESTWIN -fms-compatibility

 //expected-error at +3 {{token is not a valid binary operator in a preprocessor subexpression}}
@@ -29,3 +30,14 @@
 #ifdef and
 #warning and is defined
+#ifdef TESTWIN
+// For cl compatibility, fno-operator-names is enabled by default.
+int and;
+int bitand;
+int bitor;
+int compl;
+int not;
+int or;
+int xor;

cfe-commits mailing list
cfe-commits at lists.llvm.org<mailto:cfe-commits at lists.llvm.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170524/2ccb3f6a/attachment.html>

More information about the cfe-commits mailing list