From 36b7288a0ce9588b958e0b3a68613e9ee11cf17c Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 14 Apr 2022 15:49:01 +0200 Subject: [PATCH] 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 --- compilerplugins/clang/implicitboolconversion.cxx | 5 +++-- compilerplugins/clang/test/implicitboolconversion.cxx | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx index e61f4a14cf0f..d0bdff190807 100644 --- a/compilerplugins/clang/implicitboolconversion.cxx +++ b/compilerplugins/clang/implicitboolconversion.cxx @@ -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) { diff --git a/compilerplugins/clang/test/implicitboolconversion.cxx b/compilerplugins/clang/test/implicitboolconversion.cxx index 47c015261fef..fa5a2b84b905 100644 --- a/compilerplugins/clang/test/implicitboolconversion.cxx +++ b/compilerplugins/clang/test/implicitboolconversion.cxx @@ -12,6 +12,7 @@ #include #include +#include #include template struct Sequence @@ -35,6 +36,8 @@ template 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> s4{ { false } }; (void)s4; Wrap1 w1{ false }; - (void)w1; Sequence> s5{ { false } }; (void)s5; Wrap2 w2{ false }; (void)w2; Sequence> s6{ { false } }; (void)s6; + h(w1.element); + css::uno::Sequence s7(1); + h(s7[0]); } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */