[MSVC2012] Allow 'mutable' references

Some standard header files from MSVC2012 use 'mutable' on references, though it is directly prohibited by the standard.
Fix for http://llvm.org/PR22444
Differential Revision: http://reviews.llvm.org/D7370

llvm-svn: 228113
This commit is contained in:
Alexey Bataev 2015-02-04 04:45:32 +00:00
parent d94d25301c
commit 8f01bb983c
3 changed files with 22 additions and 3 deletions

View File

@ -1241,6 +1241,9 @@ def err_storageclass_invalid_for_member : Error<
"storage class specified for a member declaration">;
def err_mutable_function : Error<"'mutable' cannot be applied to functions">;
def err_mutable_reference : Error<"'mutable' cannot be applied to references">;
def ext_mutable_reference : ExtWarn<
"'mutable' on a reference type is a Microsoft extension">,
InGroup<Microsoft>;
def err_mutable_const : Error<"'mutable' and 'const' cannot be mixed">;
def err_mutable_nonmember : Error<
"'mutable' can only be applied to member variables">;

View File

@ -12348,7 +12348,8 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
if (!InvalidDecl && Mutable) {
unsigned DiagID = 0;
if (T->isReferenceType())
DiagID = diag::err_mutable_reference;
DiagID = getLangOpts().MSVCCompat ? diag::ext_mutable_reference
: diag::err_mutable_reference;
else if (T.isConstQualified())
DiagID = diag::err_mutable_const;
@ -12357,8 +12358,10 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
if (D && D->getDeclSpec().getStorageClassSpecLoc().isValid())
ErrLoc = D->getDeclSpec().getStorageClassSpecLoc();
Diag(ErrLoc, DiagID);
Mutable = false;
InvalidDecl = true;
if (DiagID != diag::ext_mutable_reference) {
Mutable = false;
InvalidDecl = true;
}
}
}

View File

@ -0,0 +1,13 @@
// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-compatibility
struct S {
mutable int &a; // expected-warning {{'mutable' on a reference type is a Microsoft extension}}
S(int &b) : a(b) {}
};
int main() {
int a = 0;
const S s(a);
s.a = 10;
return s.a + a;
}