diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-06-03 10:52:46 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-06-04 08:23:43 +0200 |
commit | b83ac35bf46ecbebf7f806235eca38a71e521c32 (patch) | |
tree | 660cb00ba4045c7238e9d43176196339ecf901f0 /compilerplugins | |
parent | 7b905c8f1d520ae1aaf4bd2fbb6a3325b404ea95 (diff) |
loplugin:simplifypointertobool improve (2)
to look for the
x.get() == null
pattern, which can be simplified to
!x
Change-Id: I0eddf93257ab53ab31949961d7c33ac2dd7288ea
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95400
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/simplifypointertobool.cxx | 4 | ||||
-rw-r--r-- | compilerplugins/clang/test/simplifypointertobool.cxx | 6 |
2 files changed, 4 insertions, 6 deletions
diff --git a/compilerplugins/clang/simplifypointertobool.cxx b/compilerplugins/clang/simplifypointertobool.cxx index 4f8abb52c74f..4630556984a3 100644 --- a/compilerplugins/clang/simplifypointertobool.cxx +++ b/compilerplugins/clang/simplifypointertobool.cxx @@ -423,9 +423,7 @@ bool SimplifyPointerToBool::VisitBinaryOperator(BinaryOperator const* binOp) if (ignoreLocation(binOp)) return true; auto opCode = binOp->getOpcode(); - //TODO if (opCode != BO_EQ && opCode != BO_NE) - // return true; - if (opCode != BO_NE) + if (opCode != BO_EQ && opCode != BO_NE) return true; const Expr* possibleMemberCall = nullptr; if (isa<CXXNullPtrLiteralExpr>(binOp->getLHS()->IgnoreParenImpCasts())) diff --git a/compilerplugins/clang/test/simplifypointertobool.cxx b/compilerplugins/clang/test/simplifypointertobool.cxx index 05f78d52ed78..2980003e19c7 100644 --- a/compilerplugins/clang/test/simplifypointertobool.cxx +++ b/compilerplugins/clang/test/simplifypointertobool.cxx @@ -31,7 +31,7 @@ void test2(std::shared_ptr<int> p) // expected-error@+1 {{simplify, drop the get() [loplugin:simplifypointertobool]}} if (p.get()) foo(); - // TODOexpected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} + // expected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} if (p.get() == nullptr) foo(); // TODOexpected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} @@ -40,7 +40,7 @@ void test2(std::shared_ptr<int> p) // TODOexpected-error@+1 {{simplify, convert to 'x' [loplugin:simplifypointertobool]}} if (p != nullptr) foo(); - // TODOexpected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} + // expected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} if (nullptr == p.get()) foo(); // expected-error@+1 {{simplify, convert to 'x' [loplugin:simplifypointertobool]}} @@ -66,7 +66,7 @@ void test2(css::uno::Reference<css::uno::XInterface> const& p) // expected-error@+1 {{simplify, drop the get() [loplugin:simplifypointertobool]}} if (p.get()) foo(); - // TODOexpected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} + // expected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} if (p.get() == nullptr) foo(); } |