From e02e0f4081c0807fa65548159292585c680abff3 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 26 Oct 2017 21:04:03 +0200 Subject: [PATCH] Use compat::getSubExprAsWritten; clean up Change-Id: I8f984c3b3833437f6b4d65ab99da608a6868ff74 --- .../clang/implicitboolconversion.cxx | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx index 1151a78f4384..bc18e87cf366 100644 --- a/compilerplugins/clang/implicitboolconversion.cxx +++ b/compilerplugins/clang/implicitboolconversion.cxx @@ -859,29 +859,30 @@ bool ImplicitBoolConversion::VisitImplicitCastExpr( } return true; } - ExplicitCastExpr const * sub = dyn_cast( - expr->getSubExpr()->IgnoreParenImpCasts()); - if (sub != nullptr - && (sub->getSubExpr()->IgnoreParenImpCasts()->getType().IgnoreParens() - == expr->getType().IgnoreParens()) - && isBool(sub->getSubExpr()->IgnoreParenImpCasts())) + if (auto const sub = dyn_cast( + compat::getSubExprAsWritten(expr))) { - // Ignore "normalizing cast" bool(b) from sal_Bool b to bool, then - // implicitly cast back again to sal_Bool: - if (dyn_cast(sub) != nullptr - && sub->getType()->isBooleanType() && isSalBool(expr->getType()) - && isSalBool(sub->getSubExpr()->IgnoreParenImpCasts()->getType())) + auto const subsub = compat::getSubExprAsWritten(sub); + if (subsub->getType().IgnoreParens() == expr->getType().IgnoreParens() + && isBool(subsub)) { + // Ignore "normalizing cast" bool(b) from sal_Bool b to bool, then + // implicitly cast back again to sal_Bool: + if (dyn_cast(sub) != nullptr + && sub->getType()->isBooleanType() && isSalBool(expr->getType()) + && isSalBool(subsub->getType())) + { + return true; + } + report( + DiagnosticsEngine::Warning, + ("explicit conversion (%0) from %1 to %2 implicitly cast back" + " to %3"), + expr->getLocStart()) + << sub->getCastKindName() << subsub->getType() << sub->getType() + << expr->getType() << expr->getSourceRange(); return true; } - 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; } if (expr->getType()->isBooleanType() && !isBoolExpr(expr->getSubExpr()) && !calls.empty())