Fix a couple of bugs found by Neil Booth in the const-ness checking.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51361 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index a050ab2..b0b50ba 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1004,8 +1004,13 @@
return cast<CompoundLiteralExpr>(Init)->isFileScope();
case Expr::DeclRefExprClass: {
const Decl *D = cast<DeclRefExpr>(Init)->getDecl();
- if (const VarDecl *VD = dyn_cast<VarDecl>(D))
- return VD->hasGlobalStorage();
+ if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
+ if (VD->hasGlobalStorage())
+ return false;
+ Diag(Init->getExprLoc(),
+ diag::err_init_element_not_constant, Init->getSourceRange());
+ return true;
+ }
if (isa<FunctionDecl>(D))
return false;
Diag(Init->getExprLoc(),
@@ -1032,7 +1037,7 @@
// C99 6.6p9
if (Exp->getOpcode() == UnaryOperator::Deref)
- return CheckAddressConstantExpressionLValue(Exp->getSubExpr());
+ return CheckAddressConstantExpression(Exp->getSubExpr());
Diag(Init->getExprLoc(),
diag::err_init_element_not_constant, Init->getSourceRange());