CWG issue 1405: mutable members are allowed in literal types, but can't undergo
lvalue-to-rvalue conversions in constant expressions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150145 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index 82f7fed..3d32091 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -773,11 +773,15 @@
         // emit it as a global instead.
         if (CGM.getCodeGenOpts().MergeAllConstants && Ty.isConstQualified() &&
             !NRVO && !isByRef && Ty->isLiteralType()) {
-          EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage);
+          CXXRecordDecl *RD =
+            Ty->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
+          if (!RD || !RD->hasMutableFields()) {
+            EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage);
 
-          emission.Address = 0; // signal this condition to later callbacks
-          assert(emission.wasEmittedAsGlobal());
-          return emission;
+            emission.Address = 0; // signal this condition to later callbacks
+            assert(emission.wasEmittedAsGlobal());
+            return emission;
+          }
         }
 
         // Otherwise, tell the initialization code that we're in this case.