diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-02-14 13:01:42 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-02-15 11:52:41 +0100 |
commit | e132e781d8b01684d8ef51f060e90d465a21c677 (patch) | |
tree | f18331549fdc95416a748c7792f804a39ab0a30f /compilerplugins/clang/test | |
parent | 58a2473d6672eb4ae4f55c3fe4c25ea23d932db5 (diff) |
loplugin:simplifybool extend to !(a == b) where comparison an overloaded op
Change-Id: I08fcbe2569c07f5f97269ad861fa6d38f23a7cc7
Reviewed-on: https://gerrit.libreoffice.org/67816
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/test')
-rw-r--r-- | compilerplugins/clang/test/simplifybool.cxx | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/simplifybool.cxx b/compilerplugins/clang/test/simplifybool.cxx index 2cb2e810c110..01549f320ab0 100644 --- a/compilerplugins/clang/test/simplifybool.cxx +++ b/compilerplugins/clang/test/simplifybool.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <rtl/ustring.hxx> + void f1(int a, int b) { if (!(a < b)) @@ -56,4 +58,60 @@ bool f2(E2 e) { return !!(e & E2_1); } bool f3(E3 e) { return !!(e & E3::E1); } +// record types + +struct Record1 +{ + bool operator==(const Record1&) const; +}; + +struct Record2 +{ + bool operator==(const Record2&) const; + bool operator!=(const Record2&) const; +}; + +struct Record3 +{ +}; + +bool operator==(const Record3&, const Record3&); +bool operator!=(const Record3&, const Record3&); + +void testRecord() +{ + Record1 a1; + Record1 a2; + // no warning expected, because a negated operator does not exist + bool v = !(a1 == a2); + Record2 b1; + Record2 b2; + v = !(b1 == b2); + // expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}} + Record3 c1; + Record3 c2; + v = !(c1 == c2); + // expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}} + OUString d1; + OUString d2; + v = !(d1 == d2); + // expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}} +} + +struct Record4 +{ + bool operator==(Record4 const&) const; + bool operator!=(Record4 const& other) const + { + // no warning expected + bool v = !operator==(other); + v = !(*this == other); + OUString c1; + OUString c2; + v = !(c1 == c2); + // expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}} + return v; + } +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |