r303798 - For Microsoft compatibility, set fno_operator_names

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Wed May 24 12:42:49 PDT 2017


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> 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> 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
>> Log:
>> 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
>>     cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>>     cfe/trunk/test/Preprocessor/cxx_oper_keyword.cpp
>>
>> 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,
>>                                    Opts.GNUKeywords);
>>
>> -  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/Mi
>> crosoftExtensions.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() {
>>    ++sp.V11;
>>  }
>>
>> -//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/Preproces
>> sor/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
>>
>>  #ifndef OPERATOR_NAMES
>>  //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
>>  #endif
>> +
>> +#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;
>> +#endif
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170524/50e36c46/attachment-0001.html>


More information about the cfe-commits mailing list