- Teach Expr::isConstantExpr() about InitListExpr's (and offsetof, since I noticed it was missing).
- Rename CheckInitializer() to CheckInitializerTypes().
- Removed the isStatic argument to CheckInitializerTypes() and all of it's subroutines. Checking for constant expressions is now done separately.
- Added CheckForConstantInitializer().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45840 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Expr.cpp b/AST/Expr.cpp
index 1591221..e2f6c62 100644
--- a/AST/Expr.cpp
+++ b/AST/Expr.cpp
@@ -487,7 +487,8 @@
// Get the operand value. If this is sizeof/alignof, do not evalute the
// operand. This affects C99 6.6p3.
- if (!Exp->isSizeOfAlignOfOp() &&
+ if (!Exp->isSizeOfAlignOfOp() &&
+ Exp->getOpcode() != UnaryOperator::OffsetOf &&
!Exp->getSubExpr()->isConstantExpr(Ctx, Loc))
return false;
@@ -501,6 +502,7 @@
return true; // FIXME: this is wrong.
case UnaryOperator::SizeOf:
case UnaryOperator::AlignOf:
+ case UnaryOperator::OffsetOf:
// sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) {
if (Loc) *Loc = Exp->getOperatorLoc();
@@ -560,9 +562,18 @@
return false;
return true;
}
+ case InitListExprClass: {
+ const InitListExpr *Exp = cast<InitListExpr>(this);
+ unsigned numInits = Exp->getNumInits();
+ for (unsigned i = 0; i < numInits; i++) {
+ if (!Exp->getInit(i)->isConstantExpr(Ctx, Loc)) {
+ if (Loc) *Loc = Exp->getInit(i)->getLocStart();
+ return false;
+ }
+ }
+ return true;
}
-
- return true;
+ }
}
/// isIntegerConstantExpr - this recursive routine will test if an expression is