Make Sema::CheckForConstantInitializer use Expr::Evaluate. This fixes PR3130.
llvm-svn: 60580
This commit is contained in:
parent
bd4551cced
commit
1e495d9860
|
@ -1651,8 +1651,13 @@ bool Sema::CheckArithmeticConstantExpression(const Expr* Init) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
|
bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
|
||||||
|
Expr::EvalResult Result;
|
||||||
|
|
||||||
Init = Init->IgnoreParens();
|
Init = Init->IgnoreParens();
|
||||||
|
|
||||||
|
if (Init->Evaluate(Result, Context) && !Result.HasSideEffects)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Look through CXXDefaultArgExprs; they have no meaning in this context.
|
// Look through CXXDefaultArgExprs; they have no meaning in this context.
|
||||||
if (CXXDefaultArgExpr* DAE = dyn_cast<CXXDefaultArgExpr>(Init))
|
if (CXXDefaultArgExpr* DAE = dyn_cast<CXXDefaultArgExpr>(Init))
|
||||||
return CheckForConstantInitializer(DAE->getExpr(), DclT);
|
return CheckForConstantInitializer(DAE->getExpr(), DclT);
|
||||||
|
@ -1672,6 +1677,9 @@ bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: We can probably remove some of this code below, now that
|
||||||
|
// Expr::Evaluate is doing the heavy lifting for scalars.
|
||||||
|
|
||||||
if (Init->isNullPointerConstant(Context))
|
if (Init->isNullPointerConstant(Context))
|
||||||
return false;
|
return false;
|
||||||
if (Init->getType()->isArithmeticType()) {
|
if (Init->getType()->isArithmeticType()) {
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
// RUN: clang -emit-llvm %s -o -
|
||||||
|
|
||||||
|
int a = 2.0 ? 1 : 2;
|
|
@ -19,5 +19,6 @@ int h0 = __builtin_types_compatible_p(int,float); // expected-warning {{extensio
|
||||||
|
|
||||||
short somefunc();
|
short somefunc();
|
||||||
|
|
||||||
short t = __builtin_constant_p(5353) ? 42 : somefunc(); // expected-warning {{expression is not a constant, but is accepted as one by GNU extensions}}
|
short t = __builtin_constant_p(5353) ? 42 : somefunc();
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue