Use DeclCheck at one place in loplugin:implicitboolconversion

...and add tests for those additions to isBoolExpr done in
8e4d82cd1125502c26ddaaa85c49c4aa44f65811 "loplugin:implicitboolconversion: warn
about conversions to unsigned char" (and which were added to avoid false
warnings like

> testtools/source/bridgetest/bridgetest.cxx:643:21: error: implicit conversion (IntegralToBoolean) of call argument from 'unsigned char' to 'bool' [loplugin:implicitboolconversion]
>                     (xLBT->transportPolyBoolean(
>                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

and

> cui/source/options/optaboutconfig.cxx:359:62: error: implicit conversion (IntegralToBoolean) of call argument from 'unsigned char' to 'bool' [loplugin:implicitboolconversion]
>                             sValue.append(OUString::boolean( seq[j] ));
>                                                              ^~~~~~

)

Change-Id: I0683144e1c39d31303faf678afaafd708ef7ff79
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133018
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann 2022-04-14 15:49:01 +02:00
parent 9798f8ad50
commit 36b7288a0c
2 changed files with 9 additions and 3 deletions

View File

@ -180,8 +180,9 @@ bool isBoolExpr(Expr const * expr) {
TemplateDecl const * d
= t->getTemplateName().getAsTemplateDecl();
if (d == nullptr
|| (d->getQualifiedNameAsString()
!= "com::sun::star::uno::Sequence")
|| !loplugin::DeclCheck(d->getTemplatedDecl()).Class("Sequence")
.Namespace("uno").Namespace("star").Namespace("sun").Namespace("com")
.GlobalNamespace()
|| t->getNumArgs() != 1
|| t->getArg(0).getKind() != TemplateArgument::Type)
{

View File

@ -12,6 +12,7 @@
#include <atomic>
#include <initializer_list>
#include <com/sun/star/uno/Sequence.hxx>
#include <sal/types.h>
template <typename T> struct Sequence
@ -35,6 +36,8 @@ template <typename T> struct Wrap2
bool g();
void h(bool);
void f()
{
// expected-error@+1 {{implicit conversion (IntegralCast) from 'bool' to 'int' [loplugin:implicitboolconversion]}}
@ -63,13 +66,15 @@ void f()
Sequence<Sequence<int>> s4{ { false } };
(void)s4;
Wrap1<sal_Bool> w1{ false };
(void)w1;
Sequence<Wrap1<sal_Bool>> s5{ { false } };
(void)s5;
Wrap2<sal_Bool> w2{ false };
(void)w2;
Sequence<Wrap2<sal_Bool>> s6{ { false } };
(void)s6;
h(w1.element);
css::uno::Sequence<sal_Bool> s7(1);
h(s7[0]);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */