зеркало из https://github.com/microsoft/clang-1.git
Reimplement Expr::isConstantExpr in terms of Expr::Evaluate. This fixes PR2832.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59946 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
85879ee8b5
Коммит
e8a32b855c
|
@ -622,8 +622,32 @@ Expr *Expr::IgnoreParenCasts() {
|
|||
}
|
||||
}
|
||||
|
||||
#define USE_EVALUATE
|
||||
|
||||
bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
|
||||
#ifdef USE_EVALUATE
|
||||
switch (getStmtClass()) {
|
||||
default:
|
||||
if (!isEvaluatable(Ctx)) {
|
||||
if (Loc) *Loc = getLocStart();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case StringLiteralClass:
|
||||
case ObjCStringLiteralClass:
|
||||
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))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
switch (getStmtClass()) {
|
||||
default:
|
||||
if (Loc) *Loc = getLocStart();
|
||||
|
@ -762,6 +786,7 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
|
|||
case CXXDefaultArgExprClass:
|
||||
return cast<CXXDefaultArgExpr>(this)->getExpr()->isConstantExpr(Ctx, Loc);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// isIntegerConstantExpr - this recursive routine will test if an expression is
|
||||
|
|
|
@ -18,3 +18,9 @@ void g() {
|
|||
static char a[10];
|
||||
static char *b = a;
|
||||
}
|
||||
|
||||
struct s { void *p; };
|
||||
|
||||
void foo(void) {
|
||||
static struct s var = {((void*)&((char*)0)[0])};
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче