compilerplugins/clang/implicitboolconversion.cxx |   30 +++++++++++++++++++----
 1 file changed, 25 insertions(+), 5 deletions(-)

New commits:
commit c7aee57724828c4b9d67deb930f09c494ff4d811
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Thu Mar 16 08:33:07 2023 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Thu Mar 16 09:15:49 2023 +0000

    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 <sberg...@redhat.com>

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>(

Reply via email to