From 054c0e7177cbef26942f8ca7cb7b1422ceea721c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 2 Jun 2020 10:40:26 +0200 Subject: loplugin:simplifypointertobool improve to look for the x.get() != null pattern, which can be simplified to x I'll do the x.get() == nullptr pattern in a separate patch, to reduce the chances of a mistake Change-Id: I45e0d178e75359857cdf50d712039cb526016555 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95354 Tested-by: Jenkins Reviewed-by: Noel Grandin --- .../clang/test/simplifypointertobool.cxx | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'compilerplugins/clang/test/simplifypointertobool.cxx') diff --git a/compilerplugins/clang/test/simplifypointertobool.cxx b/compilerplugins/clang/test/simplifypointertobool.cxx index e4bf14c40f45..05f78d52ed78 100644 --- a/compilerplugins/clang/test/simplifypointertobool.cxx +++ b/compilerplugins/clang/test/simplifypointertobool.cxx @@ -8,6 +8,7 @@ */ #include +#include "com/sun/star/uno/XInterface.hpp" void foo(); @@ -30,6 +31,44 @@ void test2(std::shared_ptr p) // expected-error@+1 {{simplify, drop the get() [loplugin:simplifypointertobool]}} if (p.get()) foo(); + // TODOexpected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} + if (p.get() == nullptr) + foo(); + // TODOexpected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} + if (p == nullptr) + foo(); + // TODOexpected-error@+1 {{simplify, convert to 'x' [loplugin:simplifypointertobool]}} + if (p != nullptr) + foo(); + // TODOexpected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} + if (nullptr == p.get()) + foo(); + // expected-error@+1 {{simplify, convert to 'x' [loplugin:simplifypointertobool]}} + if (p.get() != nullptr) + foo(); + // expected-error@+1 {{simplify, convert to 'x' [loplugin:simplifypointertobool]}} + if (nullptr != p.get()) + foo(); +} + +void test2(int* p) +{ + // TODOexpected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} + if (p == nullptr) + foo(); + // TODOexpected-error@+1 {{simplify, convert to 'x' [loplugin:simplifypointertobool]}} + if (p != nullptr) + foo(); +} + +void test2(css::uno::Reference const& p) +{ + // expected-error@+1 {{simplify, drop the get() [loplugin:simplifypointertobool]}} + if (p.get()) + foo(); + // TODOexpected-error@+1 {{simplify, convert to '!x' [loplugin:simplifypointertobool]}} + if (p.get() == nullptr) + foo(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit