mirror of https://github.com/microsoft/clang.git
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228113 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a13365e20e
commit
c55f729746
|
@ -1241,6 +1241,9 @@ def err_storageclass_invalid_for_member : Error<
|
||||||
"storage class specified for a member declaration">;
|
"storage class specified for a member declaration">;
|
||||||
def err_mutable_function : Error<"'mutable' cannot be applied to functions">;
|
def err_mutable_function : Error<"'mutable' cannot be applied to functions">;
|
||||||
def err_mutable_reference : Error<"'mutable' cannot be applied to references">;
|
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_const : Error<"'mutable' and 'const' cannot be mixed">;
|
||||||
def err_mutable_nonmember : Error<
|
def err_mutable_nonmember : Error<
|
||||||
"'mutable' can only be applied to member variables">;
|
"'mutable' can only be applied to member variables">;
|
||||||
|
|
|
@ -12348,7 +12348,8 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
|
||||||
if (!InvalidDecl && Mutable) {
|
if (!InvalidDecl && Mutable) {
|
||||||
unsigned DiagID = 0;
|
unsigned DiagID = 0;
|
||||||
if (T->isReferenceType())
|
if (T->isReferenceType())
|
||||||
DiagID = diag::err_mutable_reference;
|
DiagID = getLangOpts().MSVCCompat ? diag::ext_mutable_reference
|
||||||
|
: diag::err_mutable_reference;
|
||||||
else if (T.isConstQualified())
|
else if (T.isConstQualified())
|
||||||
DiagID = diag::err_mutable_const;
|
DiagID = diag::err_mutable_const;
|
||||||
|
|
||||||
|
@ -12357,8 +12358,10 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
|
||||||
if (D && D->getDeclSpec().getStorageClassSpecLoc().isValid())
|
if (D && D->getDeclSpec().getStorageClassSpecLoc().isValid())
|
||||||
ErrLoc = D->getDeclSpec().getStorageClassSpecLoc();
|
ErrLoc = D->getDeclSpec().getStorageClassSpecLoc();
|
||||||
Diag(ErrLoc, DiagID);
|
Diag(ErrLoc, DiagID);
|
||||||
Mutable = false;
|
if (DiagID != diag::ext_mutable_reference) {
|
||||||
InvalidDecl = true;
|
Mutable = false;
|
||||||
|
InvalidDecl = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue