Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td @@ -1241,6 +1241,9 @@ "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; def err_mutable_const : Error<"'mutable' and 'const' cannot be mixed">; def err_mutable_nonmember : Error< "'mutable' can only be applied to member variables">; Index: cfe/trunk/lib/Sema/SemaDecl.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp +++ cfe/trunk/lib/Sema/SemaDecl.cpp @@ -12348,7 +12348,8 @@ 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 @@ 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; + } } } Index: cfe/trunk/test/SemaCXX/ms_mutable_reference_member.cpp =================================================================== --- cfe/trunk/test/SemaCXX/ms_mutable_reference_member.cpp +++ cfe/trunk/test/SemaCXX/ms_mutable_reference_member.cpp @@ -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; +}