Make VerifyIntegerConstantExpr print extension warnings for non-ICEs.

Overall, I'm not particularly happy with the current situation regarding 
constant expression diagnostics, but I plan to improve it at some point.

llvm-svn: 70089
This commit is contained in:
Eli Friedman
2009-04-25 22:26:58 +00:00
parent 1c1595f9ef
commit bb967cc98d
2 changed files with 13 additions and 8 deletions

View File

@@ -4929,6 +4929,13 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
}
bool Sema::VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result){
llvm::APSInt ICEResult;
if (E->isIntegerConstantExpr(ICEResult, Context)) {
if (Result)
*Result = ICEResult;
return false;
}
Expr::EvalResult EvalResult;
if (!E->Evaluate(EvalResult, Context) || !EvalResult.Val.isInt() ||
@@ -4946,14 +4953,12 @@ bool Sema::VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result){
return true;
}
if (EvalResult.Diag) {
Diag(E->getExprLoc(), diag::ext_expr_not_ice) <<
E->getSourceRange();
Diag(E->getExprLoc(), diag::ext_expr_not_ice) <<
E->getSourceRange();
// Print the reason it's not a constant.
if (Diags.getDiagnosticLevel(diag::ext_expr_not_ice) != Diagnostic::Ignored)
Diag(EvalResult.DiagLoc, EvalResult.Diag);
}
if (EvalResult.Diag &&
Diags.getDiagnosticLevel(diag::ext_expr_not_ice) != Diagnostic::Ignored)
Diag(EvalResult.DiagLoc, EvalResult.Diag);
if (Result)
*Result = EvalResult.Val.getInt();

View File

@@ -13,5 +13,5 @@ enum
enum
{
SOME_VALUE= FLOAT_TO_SHORT_FIXED(0.1)
SOME_VALUE= FLOAT_TO_SHORT_FIXED(0.1) // expected-warning{{expression is not integer constant expression}}
};