Adapt loplugin:implicitboolconversion to _G_STR_NONNULL

...from glib2-devel-2.76.0-1.fc38.x86_64, causing

> libreofficekit/source/gtk/lokdocview.cxx:390:28: error: implicit conversion (IntegralCast) from 'bool' to 'int' [loplugin:implicitboolconversion]
>     pLOEvent->m_pCommand = g_strdup(pCommand);
>                            ^~~~~~~~~~~~~~~~~~
> /usr/include/glib-2.0/glib/gstrfuncs.h:212:35: note: expanded from macro 'g_strdup'
>         const char *const __str = _G_STR_NONNULL (___str);                    \
>                                   ^~~~~~~~~~~~~~~~~~~~~~~
> /usr/include/glib-2.0/glib/gstrfuncs.h:157:34: note: expanded from macro '_G_STR_NONNULL'
> #define _G_STR_NONNULL(x) ((x) + !(x))
>                                  ^~~~

Change-Id: Iec20b20992a61fd48155f338a10dc313411448f8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148948
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann 2023-03-16 08:33:07 +01:00
parent 9070c1b040
commit c7aee57724

View file

@ -691,13 +691,33 @@ bool ImplicitBoolConversion::VisitImplicitCastExpr(
if (isBool(compat::getSubExprAsWritten(expr)) && !isBool(expr)) {
// Ignore NoOp from 'sal_Bool' (aka 'unsigned char') to 'const unsigned
// char' in makeAny(b) with b of type sal_Bool:
if (expr->getCastKind() != CK_NoOp) {
if (nested.empty()) {
reportWarning(expr);
} else {
nested.top().push_back(expr);
if (expr->getCastKind() == CK_NoOp) {
return true;
}
// Ignore implicit conversions from bool to int in
//
// #define _G_STR_NONNULL(x) (x + !x)
//
// from
// <https://gitlab.gnome.org/GNOME/glib/-/commit/48730d2b30473c5eeda2badf9a65d380304477c3>
// "gstrfuncs: Add back x + !x warning workaround":
if (auto const sub = dyn_cast<UnaryOperator>(compat::getSubExprAsWritten(expr))) {
if (sub->getOpcode() == UO_LNot) {
auto const l = expr->getBeginLoc();
if (compiler.getSourceManager().isMacroBodyExpansion(l)
&& Lexer::getImmediateMacroName(
l, compiler.getSourceManager(), compiler.getLangOpts())
== "_G_STR_NONNULL")
{
return true;
}
}
}
if (nested.empty()) {
reportWarning(expr);
} else {
nested.top().push_back(expr);
}
return true;
}
if (auto const sub = dyn_cast<ExplicitCastExpr>(