[cfe-commits] r62952 - /cfe/trunk/lib/AST/Expr.cpp
Eli Friedman
eli.friedman at gmail.com
Sat Jan 24 19:12:18 PST 2009
Author: efriedma
Date: Sat Jan 24 21:12:18 2009
New Revision: 62952
URL: http://llvm.org/viewvc/llvm-project?rev=62952&view=rev
Log:
Enhancements to Expr::isConstantInitializer to deal with a few
cases it couldn't deal with before.
Modified:
cfe/trunk/lib/AST/Expr.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=62952&r1=62951&r2=62952&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sat Jan 24 21:12:18 2009
@@ -693,12 +693,14 @@
}
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 @@
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
More information about the cfe-commits
mailing list