[Libreoffice-commits] core.git: compilerplugins/clang

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Fri Nov 15 13:10:22 UTC 2019


 compilerplugins/clang/consttobool.cxx      |    5 +++++
 compilerplugins/clang/test/consttobool.cxx |   11 +++++++++++
 2 files changed, 16 insertions(+)

New commits:
commit 2a1533b0191508d4836a0f4fd1f4c8011a467d9f
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Fri Nov 15 11:20:12 2019 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Fri Nov 15 14:09:03 2019 +0100

    Add loplugin:consttobool assert-related tests
    
    ...and improve diagnostics a bit
    
    Change-Id: I3233aa1752620ddbe6fbeff93b15565921f0bc2e
    Reviewed-on: https://gerrit.libreoffice.org/82767
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/compilerplugins/clang/consttobool.cxx b/compilerplugins/clang/consttobool.cxx
index 8f7823aa8816..21fde3f547b1 100644
--- a/compilerplugins/clang/consttobool.cxx
+++ b/compilerplugins/clang/consttobool.cxx
@@ -207,6 +207,11 @@ public:
             suggestion = true;
             replacement = false;
         }
+        else if (res.isLValue())
+        {
+            suggestion = true;
+            replacement = true;
+        }
         else
         {
             suggestion = false;
diff --git a/compilerplugins/clang/test/consttobool.cxx b/compilerplugins/clang/test/consttobool.cxx
index 6110b4ba0942..684a9739b2ab 100644
--- a/compilerplugins/clang/test/consttobool.cxx
+++ b/compilerplugins/clang/test/consttobool.cxx
@@ -9,6 +9,8 @@
 
 #include <sal/config.h>
 
+#include <cassert>
+
 #include <sal/types.h>
 
 #pragma clang diagnostic ignored "-Wnull-conversion"
@@ -44,6 +46,15 @@ int main()
     b = c2;
     // expected-error at +1 {{implicit conversion of constant 3 of type 'int' to 'bool'; use 'true' instead [loplugin:consttobool]}}
     b = (c1 | c2);
+
+    assert(b); // no warnings from within assert macro itself
+    assert(b && "msg"); // no warnings for `&& "msg"`
+    if (b)
+    {
+        assert(!"msg"); // no warnings for `!"msg"`
+    }
+    // expected-error at +1 {{implicit conversion of constant &"msg"[0] of type 'const char *' to 'bool'; use 'true' instead [loplugin:consttobool]}}
+    assert("msg");
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */


More information about the Libreoffice-commits mailing list