Enhancements to Expr::isConstantInitializer to deal with a few

cases it couldn't deal with before.

llvm-svn: 62952
This commit is contained in:
Eli Friedman 2009-01-25 03:12:18 +00:00
parent 7139af42ce
commit 384da27131
1 changed files with 25 additions and 6 deletions

View File

@ -693,12 +693,14 @@ bool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) {
} }
bool Expr::isConstantInitializer(ASTContext &Ctx) const { 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()) { switch (getStmtClass()) {
default: default: break;
if (!isEvaluatable(Ctx)) {
return false;
}
break;
case StringLiteralClass: case StringLiteralClass:
return true; return true;
case CompoundLiteralExprClass: { case CompoundLiteralExprClass: {
@ -712,10 +714,27 @@ bool Expr::isConstantInitializer(ASTContext &Ctx) const {
if (!Exp->getInit(i)->isConstantInitializer(Ctx)) if (!Exp->getInit(i)->isConstantInitializer(Ctx))
return false; 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 /// isIntegerConstantExpr - this recursive routine will test if an expression is