From: Eli Friedman Date: Fri, 20 Feb 2009 02:36:22 +0000 (+0000) Subject: A few small tweaks to isConstantInitializer. (No test because this X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f4a6db271f389d6ab3cb1bc28cb5c23a7828602;p=clang A few small tweaks to isConstantInitializer. (No test because this isn't getting used by Sema or CodeGen at the moment...) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65107 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index d9db133385..b613492f14 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -794,15 +794,24 @@ bool Expr::isConstantInitializer(ASTContext &Ctx) const { // expressions, and it can't deal with aggregates; we deal with those here, // and fall back to isEvaluatable for the other cases. + // FIXME: This function assumes the variable being assigned to + // isn't a reference type! + switch (getStmtClass()) { default: break; case StringLiteralClass: return true; case CompoundLiteralExprClass: { + // This handles gcc's extension that allows global initializers like + // "struct x {int x;} x = (struct x) {};". + // FIXME: This accepts other cases it shouldn't! const Expr *Exp = cast(this)->getInitializer(); return Exp->isConstantInitializer(Ctx); } case InitListExprClass: { + // FIXME: This doesn't deal with fields with reference types correctly. + // FIXME: This incorrectly allows pointers cast to integers to be assigned + // to bitfields. const InitListExpr *Exp = cast(this); unsigned numInits = Exp->getNumInits(); for (unsigned i = 0; i < numInits; i++) { @@ -829,9 +838,6 @@ bool Expr::isConstantInitializer(ASTContext &Ctx) const { if (getType()->isRecordType()) return cast(this)->getSubExpr()->isConstantInitializer(Ctx); break; - case DesignatedInitExprClass: - return cast(this)-> - getInit()->isConstantInitializer(Ctx); } return isEvaluatable(Ctx);