diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-11-15 11:20:12 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-11-15 14:09:03 +0100 |
commit | 2a1533b0191508d4836a0f4fd1f4c8011a467d9f (patch) | |
tree | 20810f54bdd9b964d02e539ed5d1438f85af0d0d /compilerplugins | |
parent | 4b54a23a0eedbf52402dfadc3c133888ebaf588f (diff) |
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@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/consttobool.cxx | 5 | ||||
-rw-r--r-- | compilerplugins/clang/test/consttobool.cxx | 11 |
2 files changed, 16 insertions, 0 deletions
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@+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@+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: */ |