From 5a294e6a2c116010f8cb88a5e020b30888e8c642 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 9 Feb 2012 03:29:58 +0000 Subject: CWG issue 1405: mutable members are allowed in literal types, but can't undergo lvalue-to-rvalue conversions in constant expressions. llvm-svn: 150145 --- clang/lib/CodeGen/CGDecl.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'clang/lib/CodeGen/CGDecl.cpp') diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 82f7fed7bae..3d32091a4b0 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -773,11 +773,15 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) { // emit it as a global instead. if (CGM.getCodeGenOpts().MergeAllConstants && Ty.isConstQualified() && !NRVO && !isByRef && Ty->isLiteralType()) { - EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage); - - emission.Address = 0; // signal this condition to later callbacks - assert(emission.wasEmittedAsGlobal()); - return emission; + 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; + } } // Otherwise, tell the initialization code that we're in this case. -- cgit v1.2.3