diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-11-22 13:13:09 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-11-23 10:03:16 +0100 |
commit | 52dbe0c99b58bf306004e3e7f7d0d98adb16193b (patch) | |
tree | ac8e72205c1b95417488f175b76df95c07fa80ae /compilerplugins/clang/simplifybool.cxx | |
parent | b26012ef159bd420ac3bb9275607d3a1622422f7 (diff) |
Make not warning about !! in loplugin:simplifybool consistent
...so that 640e03da110d76b2c7d5ed5b8b8ba3b4367865ba "loplugin:simplifybool re-
activate the !! warning", which did not warn about
!!( nAttribs & ucb::ContentInfoAttribute::KIND_FOLDER )
in ucb/source/core/ucbcmds.cxx (involving sal_Int32 and sal_Int16), would not
have warned about
!!(nMode & nUpdateMode)
in sfx2/source/appl/workwin.cxx (ivolving o3tl::typed_flags<SfxVisibilityFlags>)
either.
Change-Id: Ibe955592951a04b1bd9a9b4e8cc502024bc1d460
Reviewed-on: https://gerrit.libreoffice.org/45083
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang/simplifybool.cxx')
-rw-r--r-- | compilerplugins/clang/simplifybool.cxx | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/compilerplugins/clang/simplifybool.cxx b/compilerplugins/clang/simplifybool.cxx index 091591f30988..260946a5fd98 100644 --- a/compilerplugins/clang/simplifybool.cxx +++ b/compilerplugins/clang/simplifybool.cxx @@ -7,10 +7,35 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <cassert> + #include "plugin.hxx" namespace { +// Like clang::Stmt::IgnoreImplicit (lib/AST/Stmt.cpp), but also looking through implicit +// UserDefinedConversion's member function call: +Expr const * ignoreAllImplicit(Expr const * expr) { + if (auto const e = dyn_cast<ExprWithCleanups>(expr)) { + expr = e->getSubExpr(); + } + if (auto const e = dyn_cast<MaterializeTemporaryExpr>(expr)) { + expr = e->GetTemporaryExpr(); + } + if (auto const e = dyn_cast<CXXBindTemporaryExpr>(expr)) { + expr = e->getSubExpr(); + } + while (auto const e = dyn_cast<ImplicitCastExpr>(expr)) { + expr = e->getSubExpr(); + if (e->getCastKind() == CK_UserDefinedConversion) { + auto const ce = cast<CXXMemberCallExpr>(expr); + assert(ce->getNumArgs() == 0); + expr = ce->getImplicitObjectArgument(); + } + } + return expr; +} + Expr const * ignoreParenImpCastAndComma(Expr const * expr) { for (;;) { expr = expr->IgnoreParenImpCasts(); @@ -94,15 +119,16 @@ bool SimplifyBool::VisitUnaryLNot(UnaryOperator const * expr) { if (e->getLocStart().isMacroID()) return true; // double logical not of an int is an idiom to convert to bool - if (!e->IgnoreImpCasts()->getType()->isBooleanType()) + auto const sub = ignoreAllImplicit(e); + if (!sub->getType()->isBooleanType()) return true; report( DiagnosticsEngine::Warning, ("double logical negation expression of the form '!!A' (with A of type" " %0) can %select{logically|literally}1 be simplified as 'A'"), expr->getLocStart()) - << e->IgnoreImpCasts()->getType() - << e->IgnoreImpCasts()->getType()->isBooleanType() + << sub->getType() + << sub->getType()->isBooleanType() << expr->getSourceRange(); return true; } |