Kaydet (Commit) 39accf65 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

loplugin:fpcomparison: Fix check for floating-point zero

...so that isZeroConstant doesn't trigger an assert inside Clang's
isCXX11ConstantExpr when expr is sizeof(x) with x being dependent on a template
argument.

Change-Id: I6bab46e64cc085d597db25994d8bfdc66417fe83
üst 7b0b9da7
......@@ -97,8 +97,7 @@ bool FpComparison::ignore(FunctionDecl* function)
static bool isZeroConstant(ASTContext& context, const Expr* expr)
{
// calling isCXX11ConstantExpr with non-arithmetic types sometimes results in a crash
if (!expr->getType()->isArithmeticType()) {
if (!expr->getType()->isFloatingType()) {
return false;
}
// prevent clang crash
......@@ -106,12 +105,11 @@ static bool isZeroConstant(ASTContext& context, const Expr* expr)
return false;
}
APValue result;
if (expr->isCXX11ConstantExpr(context, &result)
&& result.isFloat() && result.getFloat().isZero())
{
return true;
if (!expr->isCXX11ConstantExpr(context, &result)) {
return false;
}
return false;
assert(result.isFloat());
return result.getFloat().isZero();
}
bool FpComparison::VisitBinaryOperator(const BinaryOperator* binaryOp)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment