diff options
author | Nuno Lopes <nunoplopes@sapo.pt> | 2008-09-01 14:47:06 +0000 |
---|---|---|
committer | Nuno Lopes <nunoplopes@sapo.pt> | 2008-09-01 14:47:06 +0000 |
commit | f7e37ce8400d5ba3b0613116034aaa30e6a70b3e (patch) | |
tree | ba53417a855865938d6c47b95da1cb3d9965cd69 /lib/Sema/SemaDecl.cpp | |
parent | b381aac9bae6d608c72267dd0ed08ec6369e94e4 (diff) |
make CheckArithmeticConstantExpression() aware of &foo and pointers
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55607 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 599f0ba61b..bf7c690ac2 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1076,6 +1076,13 @@ bool Sema::CheckArithmeticConstantExpression(const Expr* Init) { const Decl *D = cast<DeclRefExpr>(Init)->getDecl(); if (isa<EnumConstantDecl>(D)) return false; + + if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) { + QualType Ty = VD->getType(); + if (Ty->isPointerLikeType() || Ty->isArrayType()) + return false; + } + Diag(Init->getExprLoc(), diag::err_init_element_not_constant, Init->getSourceRange()); return true; @@ -1098,6 +1105,8 @@ bool Sema::CheckArithmeticConstantExpression(const Expr* Init) { Diag(Init->getExprLoc(), diag::err_init_element_not_constant, Init->getSourceRange()); return true; + case UnaryOperator::AddrOf: + return false; case UnaryOperator::SizeOf: case UnaryOperator::AlignOf: case UnaryOperator::OffsetOf: @@ -1160,12 +1169,7 @@ bool Sema::CheckArithmeticConstantExpression(const Expr* Init) { case Expr::ImplicitCastExprClass: case Expr::ExplicitCastExprClass: { const Expr *SubExpr = cast<CastExpr>(Init)->getSubExpr(); - if (SubExpr->getType()->isArithmeticType()) - return CheckArithmeticConstantExpression(SubExpr); - - Diag(Init->getExprLoc(), - diag::err_init_element_not_constant, Init->getSourceRange()); - return true; + return CheckArithmeticConstantExpression(SubExpr); } case Expr::ConditionalOperatorClass: { const ConditionalOperator *Exp = cast<ConditionalOperator>(Init); |