When we emit a non-constant initializer for a global variable of

reference type, make sure that the initializer we build is the
of the appropriate type for the *reference*, not for the thing that it
refers to. Fixes PR7050.

llvm-svn: 103115
This commit is contained in:
Douglas Gregor
2010-05-05 20:15:55 +00:00
parent e36cd72e38
commit d450f06ef4
2 changed files with 32 additions and 2 deletions

View File

@@ -1101,10 +1101,12 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
assert(!ASTTy->isIncompleteType() && "Unexpected incomplete type");
Init = EmitNullConstant(D->getType());
} else {
Init = EmitConstantExpr(InitExpr, D->getType());
Init = EmitConstantExpr(InitExpr, D->getType());
if (!Init) {
QualType T = InitExpr->getType();
if (D->getType()->isReferenceType())
T = D->getType();
if (getLangOptions().CPlusPlus) {
EmitCXXGlobalVarDeclInitFunc(D);
Init = EmitNullConstant(T);