r228113 - [MSVC2012] Allow 'mutable' references
Alexey Bataev
a.bataev at hotmail.com
Tue Feb 3 20:45:33 PST 2015
Author: abataev
Date: Tue Feb 3 22:45:32 2015
New Revision: 228113
URL: http://llvm.org/viewvc/llvm-project?rev=228113&view=rev
Log:
[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
Added:
cfe/trunk/test/SemaCXX/ms_mutable_reference_member.cpp (with props)
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=228113&r1=228112&r2=228113&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Feb 3 22:45:32 2015
@@ -1241,6 +1241,9 @@ def err_storageclass_invalid_for_member
"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">;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=228113&r1=228112&r2=228113&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Feb 3 22:45:32 2015
@@ -12348,7 +12348,8 @@ FieldDecl *Sema::CheckFieldDecl(Declarat
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(Declarat
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;
+ }
}
}
Added: cfe/trunk/test/SemaCXX/ms_mutable_reference_member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms_mutable_reference_member.cpp?rev=228113&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/ms_mutable_reference_member.cpp (added)
+++ cfe/trunk/test/SemaCXX/ms_mutable_reference_member.cpp Tue Feb 3 22:45:32 2015
@@ -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;
+}
Propchange: cfe/trunk/test/SemaCXX/ms_mutable_reference_member.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/SemaCXX/ms_mutable_reference_member.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: cfe/trunk/test/SemaCXX/ms_mutable_reference_member.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list