diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-09 03:29:58 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-09 03:29:58 +0000 |
commit | b4e5e286a5cd156247720b1eb204abaa8e09568d (patch) | |
tree | c7d19ed16dffe977973cb5c69ef9815c580d4672 /lib/CodeGen/CGDecl.cpp | |
parent | 0ca7e8bf904d1c2cf70d271f3a06c1d71ff7e4fb (diff) |
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
Diffstat (limited to 'lib/CodeGen/CGDecl.cpp')
-rw-r--r-- | lib/CodeGen/CGDecl.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index 82f7fed7ba..3d32091a4b 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/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. |