implicitboolconversion: also warn about redundant explicit casts

Change-Id: Ib89b4c12d2cdca873a9fe9a509d7a123977652a7
This commit is contained in:
Stephan Bergmann 2014-01-29 15:42:04 +01:00
parent dfe30f1e3b
commit 81760e2702

View File

@ -521,6 +521,22 @@ bool ImplicitBoolConversion::VisitImplicitCastExpr(
} else {
nested.top().push_back(expr);
}
} else {
ExplicitCastExpr const * sub = dyn_cast<ExplicitCastExpr>(
expr->getSubExpr()->IgnoreParenImpCasts());
if (sub != nullptr
&& (sub->getSubExpr()->IgnoreParenImpCasts()->getType().IgnoreParens()
== expr->getType().IgnoreParens())
&& isBool(sub->getSubExpr()->IgnoreParenImpCasts()))
{
report(
DiagnosticsEngine::Warning,
"explicit conversion (%0) from %1 to %2 implicitly cast back to %3",
expr->getLocStart())
<< sub->getCastKindName()
<< sub->getSubExpr()->IgnoreParenImpCasts()->getType()
<< sub->getType() << expr->getType() << expr->getSourceRange();
}
}
return true;
}