diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2023-03-16 08:33:07 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2023-03-16 09:15:49 +0000 |
commit | c7aee57724828c4b9d67deb930f09c494ff4d811 (patch) | |
tree | 86837f4abdc647e0d8cbbcddd7415227f64e695b /compilerplugins | |
parent | 9070c1b0404fb72d2553f6fa8f702e70c0abb269 (diff) |
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>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/implicitboolconversion.cxx | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx index cdf1d762cb5b..64bc97ff4999 100644 --- a/compilerplugins/clang/implicitboolconversion.cxx +++ b/compilerplugins/clang/implicitboolconversion.cxx @@ -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>( |