aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-01-25 03:12:18 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-01-25 03:12:18 +0000
commitc39dc9a25a9d74a5302e8567a4d3fc008212024c (patch)
tree2dfef02c4f2d416a20c74b282c4dd5026e9c73b7 /lib/AST/Expr.cpp
parentc9e8f606787b0bc0c3b08e566b87cc1751694168 (diff)
Enhancements to Expr::isConstantInitializer to deal with a few
cases it couldn't deal with before. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62952 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Expr.cpp')
-rw-r--r--lib/AST/Expr.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 86f1cd9fdb..1bb404ffea 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -693,12 +693,14 @@ bool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) {
}
bool Expr::isConstantInitializer(ASTContext &Ctx) const {
+ // This function is attempting whether an expression is an initializer
+ // which can be evaluated at compile-time. isEvaluatable handles most
+ // of the cases, but it can't deal with some initializer-specific
+ // expressions, and it can't deal with aggregates; we deal with those here,
+ // and fall back to isEvaluatable for the other cases.
+
switch (getStmtClass()) {
- default:
- if (!isEvaluatable(Ctx)) {
- return false;
- }
- break;
+ default: break;
case StringLiteralClass:
return true;
case CompoundLiteralExprClass: {
@@ -712,10 +714,27 @@ bool Expr::isConstantInitializer(ASTContext &Ctx) const {
if (!Exp->getInit(i)->isConstantInitializer(Ctx))
return false;
}
+ return true;
}
+ case ParenExprClass: {
+ return cast<ParenExpr>(this)->getSubExpr()->isConstantInitializer(Ctx);
+ }
+ case UnaryOperatorClass: {
+ const UnaryOperator* Exp = cast<UnaryOperator>(this);
+ if (Exp->getOpcode() == UnaryOperator::Extension)
+ return Exp->getSubExpr()->isConstantInitializer(Ctx);
+ break;
+ }
+ case CStyleCastExprClass:
+ // Handle casts with a destination that's a struct or union; this
+ // deals with both the gcc no-op struct cast extension and the
+ // cast-to-union extension.
+ if (getType()->isRecordType())
+ return cast<CastExpr>(this)->getSubExpr()->isConstantInitializer(Ctx);
+ break;
}
- return true;
+ return isEvaluatable(Ctx);
}
/// isIntegerConstantExpr - this recursive routine will test if an expression is