When determining whether we can make a declaration into a global

constant, also consider whether it's a class type that has any mutable
fields. If so, it can't be a global constant.

llvm-svn: 131276
This commit is contained in:
Douglas Gregor
2011-05-13 01:05:07 +00:00
parent 94f9cbf998
commit 61226d3fcf
7 changed files with 38 additions and 20 deletions

View File

@@ -946,7 +946,9 @@ static bool DeclIsConstantGlobal(ASTContext &Context, const VarDecl *D,
if (Context.getLangOptions().CPlusPlus) {
if (const RecordType *Record
= Context.getBaseElementType(D->getType())->getAs<RecordType>())
return ConstantInit && cast<CXXRecordDecl>(Record->getDecl())->isPOD();
return ConstantInit &&
cast<CXXRecordDecl>(Record->getDecl())->isPOD() &&
!cast<CXXRecordDecl>(Record->getDecl())->hasMutableFields();
}
return true;