compilerplugins/clang/test/simplifybool.cxx | 176 --------------------------- solenv/CompilerTest_compilerplugins_clang.mk | 1 solenv/clang-format/excludelist | 2 3 files changed, 1 insertion(+), 178 deletions(-)
New commits: commit eb515f11caae5d1b30f7c306fc32111a0cf617b2 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Wed Nov 17 10:02:06 2021 +0100 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Wed Nov 17 12:48:36 2021 +0100 retire loplugin:simplifybool The plugin was originally written to rewrite dumb old OOo code like 'variable != 1 ? true : false'. All that code has already been rewritten, and now this plugin just enforces matter-of-taste stylistics on new code. Change-Id: I8cd2accd7c0ac365b75dcba51a9049bf9e293869 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125346 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/compilerplugins/clang/simplifybool.cxx b/compilerplugins/clang/store/simplifybool.cxx similarity index 100% rename from compilerplugins/clang/simplifybool.cxx rename to compilerplugins/clang/store/simplifybool.cxx diff --git a/compilerplugins/clang/test/simplifybool.cxx b/compilerplugins/clang/test/simplifybool.cxx deleted file mode 100644 index a32acccd6c19..000000000000 --- a/compilerplugins/clang/test/simplifybool.cxx +++ /dev/null @@ -1,176 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include <rtl/ustring.hxx> -// expected-note@rtl/ustring.hxx:* 2 {{the presumed corresponding negated operator for 'rtl::OUString' and 'rtl::OUString' is declared here [loplugin:simplifybool]}} -#include <rtl/string.hxx> -// expected-note@rtl/string.hxx:* {{the presumed corresponding negated operator for 'rtl::OString' and 'rtl::OString' is declared here [loplugin:simplifybool]}} -#include <basegfx/vector/b3dvector.hxx> -// expected-note@basegfx/tuple/b3dtuple.hxx:* {{the presumed corresponding negated operator for 'basegfx::B3DVector' and 'basegfx::B3DVector' is declared here [loplugin:simplifybool]}} - -#include <map> - -#pragma clang diagnostic ignored "-Wunknown-warning-option" // for Clang < 13 -#pragma clang diagnostic ignored "-Wunused-but-set-variable" - -namespace group1 -{ -void f1(int a, int b) -{ - if (!(a < b)) - { // expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}} - a = b; - } -}; - -void f2(float a, float b) -{ - // no warning expected - if (!(a < b)) - { - a = b; - } -}; -}; - -// Consistently either warn about all or none of the below occurrences of "!!": -namespace group2 -{ -enum E1 -{ - E1_1 = 1 -}; - -enum E2 -{ - E2_1 = 1 -}; -E2 operator&(E2 e1, E2 e2); -bool operator!(E2 e); - -enum class E3 -{ - E1 = 1 -}; -struct W -{ - operator bool(); -}; -W operator&(E3 e1, E3 e2); - -bool f0(int n) { return !!(n & 1); } - -bool f1(E1 e) { return !!(e & E1_1); } - -bool f2(E2 e) { return !!(e & E2_1); } - -bool f3(E3 e) { return !!(e & E3::E1); } -}; - -// record types -namespace group3 -{ -struct Record1 -{ - bool operator==(const Record1&) const; -}; - -struct Record2 -{ - bool operator==(const Record2&) const; - bool operator!=(const Record2&) const; - // expected-note@-1 {{the presumed corresponding negated operator for 'group3::Record2' and 'group3::Record2' is declared here [loplugin:simplifybool]}} -}; - -struct Record3 -{ -}; - -bool operator==(const Record3&, const Record3&); -bool operator!=(const Record3&, const Record3&); -// expected-note@-1 {{the presumed corresponding negated operator for 'group3::Record3' and 'group3::Record3' is declared here [loplugin:simplifybool]}} - -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]}} - OString e1; - OString e2; - v = !(e1 == e2); - // expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}} - - // the operator != is in a base-class, and the param is a base-type - basegfx::B3DVector f1; - basegfx::B3DVector f2; - v = !(f1 == f2); - // 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; - } -}; -}; - -namespace group4 -{ -bool foo1(bool a, bool b) -{ - return !(!a && !b); - // expected-error@-1 {{logical negation of logical op containing negation, can be simplified [loplugin:simplifybool]}} -} -bool foo2(int a, bool b) -{ - return !(a != 1 && !b); - // expected-error@-1 {{logical negation of logical op containing negation, can be simplified [loplugin:simplifybool]}} -} -bool foo3(int a, bool b) -{ - // no warning expected - return !(a != 1 && b); -} -}; - -namespace group5 -{ -bool foo1(std::map<int, int>* pActions, int aKey) -{ - auto aIter = pActions->find(aKey); - //TODO this doesn't work yet because I'd need to implement conversion operators during method/func lookup - return !(aIter == pActions->end()); - // expected-error@-1 {{logical negation of comparison operator, can be simplified by inverting operator [loplugin:simplifybool]}} -} -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk index 75afd793843e..93ebf8468228 100644 --- a/solenv/CompilerTest_compilerplugins_clang.mk +++ b/solenv/CompilerTest_compilerplugins_clang.mk @@ -76,7 +76,6 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \ compilerplugins/clang/test/selfinit \ compilerplugins/clang/test/sequentialassign \ compilerplugins/clang/test/shouldreturnbool \ - compilerplugins/clang/test/simplifybool \ compilerplugins/clang/test/simplifyconstruct \ compilerplugins/clang/test/simplifydynamiccast \ compilerplugins/clang/test/simplifypointertobool \ diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index 1fd086ffb285..456d168f500d 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -1524,7 +1524,6 @@ compilerplugins/clang/sfxpoolitem.cxx compilerplugins/clang/sharedvisitor/analyzer.cxx compilerplugins/clang/sharedvisitor/dummyplugin.hxx compilerplugins/clang/sharedvisitor/generator.cxx -compilerplugins/clang/simplifybool.cxx compilerplugins/clang/singlevalfields.cxx compilerplugins/clang/staticaccess.cxx compilerplugins/clang/staticmethods.cxx @@ -1557,6 +1556,7 @@ compilerplugins/clang/store/returnunique.cxx compilerplugins/clang/store/revisibility.cxx compilerplugins/clang/store/rtlconstasciimacro.cxx compilerplugins/clang/store/sfxitemsetrewrite.cxx +compilerplugins/clang/store/simplifybool.cxx compilerplugins/clang/store/stdexception.cxx compilerplugins/clang/store/stylepolice.cxx compilerplugins/clang/store/svstreamoutputoperators.cxx