[PATCH] [MSVC2012] Allow 'mutable' references (fix for http://llvm.org/PR22444)

Richard Smith richard at metafoo.co.uk
Wed Feb 4 14:54:17 PST 2015


On Tue, Feb 3, 2015 at 6:32 PM, Bataev, Alexey <a.bataev at hotmail.com> wrote:

>  Hi Richard,
> MSVC cl compiler allows mutable references even in user code, not only in
> system header files. I checked it and both 2012, 2013 accepts the code from
> the test.
>

That's beside the point. We're not trying to accept all the nonsense that
MSVC accepts, only the extensions that are needed to get real code to work.
Thus we would take patches for bugs/extensions that are used in system
headers (and ideally these cases should still give errors if used outside
system headers), and for bugs/extensions that are very common in user code.

I'll add extension warning.
>
> Best regards,
> Alexey Bataev
> =============
> Software Engineer
> Intel Compiler Team
>
> 03.02.2015 20:25, Richard Smith пишет:
>
> Please emit a warning when this extension is used. If we're only doing
> this to support a system header, you could even make it a DefaultError
> ExtWarn. Other than that, this looks fine.
> On 3 Feb 2015 02:32, "Alexey Bataev" <a.bataev at hotmail.com> wrote:
>
>> Hi rsmith,
>>
>> Some standard header files from MSVC2012 use 'mutable' on references,
>> though it is directly prohibited by the standard.
>>
>> http://reviews.llvm.org/D7370
>>
>> Files:
>>   lib/Sema/SemaDecl.cpp
>>   test/SemaCXX/ms_mutable_reference_member.cpp
>>
>> Index: lib/Sema/SemaDecl.cpp
>> ===================================================================
>> --- lib/Sema/SemaDecl.cpp
>> +++ lib/Sema/SemaDecl.cpp
>> @@ -12347,7 +12347,7 @@
>>    // Check that 'mutable' is consistent with the type of the declaration.
>>    if (!InvalidDecl && Mutable) {
>>      unsigned DiagID = 0;
>> -    if (T->isReferenceType())
>> +    if (!getLangOpts().MSVCCompat && T->isReferenceType())
>>        DiagID = diag::err_mutable_reference;
>>      else if (T.isConstQualified())
>>        DiagID = diag::err_mutable_const;
>> Index: test/SemaCXX/ms_mutable_reference_member.cpp
>> ===================================================================
>> --- test/SemaCXX/ms_mutable_reference_member.cpp
>> +++ test/SemaCXX/ms_mutable_reference_member.cpp
>> @@ -0,0 +1,14 @@
>> +// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-compatibility
>> +// expected-no-diagnostics
>> +
>> +struct S {
>> +  mutable int &a;
>> +  S(int &b) : a(b) {}
>> +};
>> +
>> +int main() {
>> +  int a = 0;
>> +  const S s(a);
>> +  s.a = 10;
>> +  return s.a + a;
>> +}
>>
>> EMAIL PREFERENCES
>>   http://reviews.llvm.org/settings/panel/emailpreferences/
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150204/548212ac/attachment.html>


More information about the cfe-commits mailing list