Commit Graph

2262 Commits

Author SHA1 Message Date
Stephan Bergmann
7e403195e5 Introduce o3tl::optional as an alias for std::optional
...with a boost::optional fallback for Xcode < 10 (as std::optional is only
available starting with Xcode 10 according to
<https://en.cppreference.com/w/cpp/compiler_support>, and our baseline for iOS
and macOS is still Xcode 9.3 according to README.md).  And mechanically rewrite
all code to use o3tl::optional instead of boost::optional.

One immediate benefit is that disabling -Wmaybe-uninitialized for GCC as per
fed7c3deb3 "Slience bogus
-Werror=maybe-uninitialized" should no longer be necessary (and whose check
happened to no longer trigger for GCC 10 trunk, even though that compiler would
still emit bogus -Wmaybe-uninitialized for uses of boost::optional under
--enable-optimized, which made me ponder whether this switch from
boost::optional to std::optional would be a useful thing to do; I keep that
configure.ac check for now, though, and will only remove it in a follow up
commit).

Another longer-term benefit is that the code is now already in good shape for an
eventual switch to std::optional (a switch we would have done anyway once we no
longer need to support Xcode < 10).

Only desktop/qa/desktop_lib/test_desktop_lib.cxx heavily uses
boost::property_tree::ptree::get_child_optional returning boost::optional, so
let it keep using boost::optional for now.

After a number of preceding commits have paved the way for this change, this
commit is completely mechanical, done with

> git ls-files -z | grep -vz -e '^bin/find-unneeded-includes$' -e '^configure.ac$' -e '^desktop/qa/desktop_lib/test_desktop_lib.cxx$' -e '^dictionaries$' -e '^external/' -e '^helpcontent2$' -e '^include/IwyuFilter_include.yaml$' -e '^sc/IwyuFilter_sc.yaml$' -e '^solenv/gdb/boost/optional.py$' -e '^solenv/vs/LibreOffice.natvis$' -e '^translations$' -e '\.svg$' | xargs -0 sed -i -E -e 's|\<boost(/optional)?/optional\.hpp\>|o3tl/optional.hxx|g' -e 's/\<boost(\s*)::(\s*)(make_)?optional\>/o3tl\1::\2\3optional/g' -e 's/\<boost(\s*)::(\s*)none\>/o3tl\1::\2nullopt/g'

(before committing include/o3tl/optional.hxx, and relying on some GNU features).
It excludes some files where mention of boost::optional et al should apparently
not be changed (and the sub-repo directory stubs).  It turned out that all uses
of boost::none across the code base were in combination with boost::optional, so
had all to be rewritten as o3tl::nullopt.

Change-Id: Ibfd9f4b3d5a8aee6e6eed310b988c4e5ffd8b11b
Reviewed-on: https://gerrit.libreoffice.org/84128
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-12-01 14:57:16 +01:00
Noel Grandin
9f38f9304e loplugin:mergeclasses
don't filter out "Base", reveals some interesting stuff

Change-Id: I62a36e70bce8e6e1346f78395dc1d32fbd8a0ddd
Reviewed-on: https://gerrit.libreoffice.org/84107
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-30 21:33:01 +01:00
Noel Grandin
964dec70d0 loplugin:unusedmethods
Change-Id: Ie92b52eabc425a4688b6d4f7cfb547ad59f4afc4
Reviewed-on: https://gerrit.libreoffice.org/84106
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-30 21:32:46 +01:00
Stephan Bergmann
b2c3528cc4 ...and take implicit const casts into account
...following up on 4f8a744c4f "Make
loplugin:unnecessaryparen treat member expressions consistently"

Change-Id: I444d2995e88990c3c6fa2b912ef68032daf2cad9
Reviewed-on: https://gerrit.libreoffice.org/84112
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-30 14:59:33 +01:00
Stephan Bergmann
4f8a744c4f Make loplugin:unnecessaryparen treat member expressions consistently
Stumbled across a warning starting to get emitted for some

  !(p->x)

when I temporarily changed x from boost::optional (which has a member operator!)
to std::optional (which instead implicitly uses a member conversion operator to
bool).  (That is, for the new

   static int foo3(Foo2 & foo) {
        (void) !(foo.p);
        (void) !(foo.b);
        (void) !(foo.n);
        return (foo.p) ? 1 : 0;
    }

test, the first, third, and fourth body lines never warned, while the second one
erroneously warned without this fix.)

Change-Id: I60f6941aaa3a73db0f1373c954e47aa68d703170
Reviewed-on: https://gerrit.libreoffice.org/84079
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-29 22:02:52 +01:00
Caolán McNamara
b24fc665c8 unnecessary virtual
Change-Id: I918a8c51e55919555108c075d396b04b4dcafbd1
Reviewed-on: https://gerrit.libreoffice.org/84061
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
2019-11-29 18:10:48 +01:00
Luboš Luňák
a8b73758e7 disable checkconfigmacros compiler check for UnpackedTarball
When building code using Skia, macros for Skia are defined
in config_skia.h, and Skia uses #ifdef to check for them, but that's
ok, and we neither care nor can do much about it.

Change-Id: I0029f0d82b26638e0395efec06c03303333ec1e9
2019-11-27 09:55:08 +01:00
Stephan Bergmann
27005a72fd loplugin:indentation no longer needs to blacklist binaryurp/source/bridge.cxx
...since bfaf25f593 "Silence
-Werror,-Wunused-variable (clang-cl)" taught it about leading [[maybe_unused]].

Change-Id: I0d3baf66623c50cfb35d3923273fb1129f66213f
Reviewed-on: https://gerrit.libreoffice.org/83728
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-26 11:28:07 +01:00
Stephan Bergmann
95d8b368d1 Adapt to clang::MaterializeTemporaryExpr::GetTemparyExpr rename
...in <https://github.com/llvm/llvm-project/commit/
b0561b3346e7bf0ae974995ca95b917eebde18e1> "[NFC] Refactor representation of
materialized temporaries"

Change-Id: I02fbf6765f9713e4d457f07521129cc9d8db5751
Reviewed-on: https://gerrit.libreoffice.org/83669
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-26 07:12:38 +01:00
Stephan Bergmann
28f8a26fa1 loplugin:implicitboolconversion: Filter out bool -> std::atomic<bool>
...as used since patch set 8 of <https://gerrit.libreoffice.org/#/c/81542/8>
"WIP: tdf#120006 New Document converter"

Change-Id: I79c2237a2e5839162272c0d49bdb4d87c9e35102
Reviewed-on: https://gerrit.libreoffice.org/83655
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-26 07:12:15 +01:00
Luboš Luňák
62625aa76b use -Xclang -fno-pch-timestamp also for Clang PCH in compilerplugins
We already use that normally, the build system should generally take
care of this by gmake dependencies. One exception is system headers,
but those usually do not really change even if their timestamps do,
so this should prevent Clang from giving an error about this after
system headers update (which should be harmless, and if it isn't
then I suppose either something else such as compiler upgrade
should trigger a rebuild, or cleaning needs to be done manually).

Change-Id: I60581c0d2d3233aadc60e1c90bd62cb9ad684ba2
Reviewed-on: https://gerrit.libreoffice.org/83662
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
2019-11-25 21:57:13 +01:00
Stephan Bergmann
f853ec317f Extend loplugin:external to warn about classes
...following up on 314f15bff0 "Extend
loplugin:external to warn about enums".

Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:

  filter/source/svg/svgexport.cxx
  sc/source/filter/excel/xelink.cxx
  sc/source/filter/excel/xilink.cxx
  svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx

All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage.  (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)

For friend declarations using elaborate type specifiers, like

  class C1 {};
  class C2 { friend class C1; };

* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")

* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".

Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace.  But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".

Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.

And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.

And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is.  GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>)  The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.

Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-22 12:57:32 +01:00
Noel Grandin
b07b192720 loplugin:unusedfields
Change-Id: Ic4cb8444123864fdaee64960f00a05b3066ae5fc
Reviewed-on: https://gerrit.libreoffice.org/83387
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-21 18:27:56 +01:00
Stephan Bergmann
df24a0dc14 loplugin:redundantfcast: Don't warn about cast from braced-init-list
...in non-deduced context.  That means that the necessary cast in
8432294498 "Simplify sequence initialization"
(cf. <https://gerrit.libreoffice.org/#/c/82974/4/>) no longer causes a false
positive, and doesn't need to use comphelper::OUStringLiteralList.

Change-Id: I788da61cc0be82d2166653760e527bb18e366c99
Reviewed-on: https://gerrit.libreoffice.org/83291
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-20 20:53:01 +01:00
Noel Grandin
e58d4cc1dd loplugin:unusedmethods
Change-Id: Id5f7a9c34d1d159dd0f930a4ce66871bdd3796c1
Reviewed-on: https://gerrit.libreoffice.org/83305
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-20 20:04:36 +01:00
Noel Grandin
98f2bd667c loplugin:unusedmethods
Remove a filtering step in the python script that was hiding some
results

Change-Id: Id94268f150902405ab197c077f18aaedf98845fc
Reviewed-on: https://gerrit.libreoffice.org/83256
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-20 09:59:17 +01:00
Stephan Bergmann
c5e5afbb4e Fix loplugin:fakebool (clang-cl)
...where it failed with

> In file included from C:/lo-clang/core/extensions/source/activex/SOActiveX.cxx:23:
> C:/lo-clang/core/extensions/source/activex/SOActiveX.h(160,1): error: VarDecl, use "bool" instead of 'BOOL' (aka 'int') [loplugin:fakebool]
> BEGIN_MSG_MAP(CSOActiveX)
> ^~~~~~~~~~~~~~~~~~~~~~~~~
> C:/PROGRA~2/MIB055~1/2019/COMMUN~1/VC/Tools/MSVC/1423~1.281/atlmfc/include\atlwin.h(2692,3): note: expanded from macro 'BEGIN_MSG_MAP'
>                 BOOL bHandled = TRUE; \
>                 ^~~~~~~~~~~~~~~~~~~~

and no idea why I did the getImmediateMacroCallerLoc call in
913d34ec6b "Extend loplugin:salbool to
loplugin:fakebool".  Removing it doesn't cause any issues at least with my local
Linux and Windows --enable-compiler-plugins builds.

Change-Id: I64bd906a34e724aefe980ce8ff2b675e8fb2ec8a
Reviewed-on: https://gerrit.libreoffice.org/83212
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 21:34:45 +01:00
Noel Grandin
80530986a7 loplugin:unusedenumconstants
Change-Id: Iecfe5d0ba8d7b287aad798daf2c3e0a7c1a5f1d3
Reviewed-on: https://gerrit.libreoffice.org/83191
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-19 20:11:30 +01:00
Stephan Bergmann
d273ea2a43 Fix loplugin:fakebool (clang-cl)
...where it failed with

> [build CXX] setup_native/source/win32/customactions/sellang/sorttree.cxx
> C:/lo-clang/core/setup_native/source/win32/customactions/sellang/sorttree.cxx(43,5): error: CStyleCastExpr, suspicious cast from 'LRESULT' (aka 'long long') to 'BOOL' (aka 'int') [loplugin:fakebool]
>     TreeView_SortChildren(hwndTV, dicts, TRUE);
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> C:/PROGRA~2/WI3CF2~1/10/Include/10.0.18362.0/um\commctrl.h(5227,5): note: expanded from macro 'TreeView_SortChildren'
>     (BOOL)SNDMSG((hwnd), TVM_SORTCHILDREN, (WPARAM)(recurse), (LPARAM)(HTREEITEM)(hitem))
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> C:/lo-clang/core/setup_native/source/win32/customactions/sellang/sorttree.cxx(43,5): error: conversion from 'LRESULT' (aka 'long long') to 'BOOL' (aka 'int') [loplugin:fakebool]
>     TreeView_SortChildren(hwndTV, dicts, TRUE);
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> C:/PROGRA~2/WI3CF2~1/10/Include/10.0.18362.0/um\commctrl.h(5227,11): note: expanded from macro 'TreeView_SortChildren'
>     (BOOL)SNDMSG((hwnd), TVM_SORTCHILDREN, (WPARAM)(recurse), (LPARAM)(HTREEITEM)(hitem))
>           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> C:/PROGRA~2/WI3CF2~1/10/Include/10.0.18362.0/um\prsht.h(73,16): note: expanded from macro 'SNDMSG'
> #define SNDMSG ::SendMessage
>                ^

(And the improved check in FakeBool::VisitImplicitCastExpr nicely removes the
need to list all the individual false/true macros.)

Change-Id: I815172f32f493bba336008aaacc00545e61ada7b
Reviewed-on: https://gerrit.libreoffice.org/83215
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 18:30:47 +01:00
Jan-Marek Glogowski
852a0f9cd8 Rename GlyphCache to FreetypeManager
And while at it remove the unneeded getPlatformGlyphCache
abstraction.

Change-Id: Id5cad751eda9e6bf177dfb4816280d7c5af7066a
Reviewed-on: https://gerrit.libreoffice.org/83125
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
2019-11-19 03:14:45 +01:00
Stephan Bergmann
d7643c6a70 Missing includes
...with recent Clang trunk

Change-Id: I9ea0f1692df8d269356df0d6b20ea2173f632425
Reviewed-on: https://gerrit.libreoffice.org/83086
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-18 17:29:17 +01:00
Chris Sherlock
729883cc42 compilerplugins: fix ambiguous type warnings
Errors were:

/home/chris/repos/libreoffice-latest/compilerplugins/clang/sharedvisitor/analyzer.cxx:80:40: error: reference to 'PointerType' is ambiguous
        if (auto const t = type->getAs<PointerType>())

/home/chris/repos/libreoffice-latest/compilerplugins/clang/external.cxx:61:44: error: reference to 'PointerType' is ambiguous
        else if (auto const t3 = t1->getAs<PointerType>())

Change-Id: Ia5b7add8f2b3160fa3198ed127785bdd61c74796
Reviewed-on: https://gerrit.libreoffice.org/83030
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
2019-11-18 13:56:08 +01:00
Andrea Gelmini
4e053538db Fix typos
Change-Id: I9251205c47f26be7695496b5887b849fcf1335f1
Reviewed-on: https://gerrit.libreoffice.org/82814
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Julien Nabet <serval2412@yahoo.fr>
2019-11-17 08:32:34 +01:00
Noel Grandin
f10b43f9d1 loplugin:unusedmethods
Change-Id: I04deb5a1dee5b8a9a4508d28552ffe0b67288993
Reviewed-on: https://gerrit.libreoffice.org/82977
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-17 07:15:22 +01:00
Stephan Bergmann
314f15bff0 Extend loplugin:external to warn about enums
To mitigate the dangers of silently breaking ADL when moving enums into unnamed
namespaces (see the commit message of 206b5b2661
"New loplugin:external"), note all functions that are affected.  (The plan is to
extend loplugin:external further to also warn about classes and class templates,
and the code to identify affected functions already takes that into account, so
some parts of that code are not actually relevant for enums.)

But it appears that none of the functions that are actually affected by the
changes in this commit relied on being found through ADL, so no adaptions were
necessary for them.

(clang::DeclContext::collectAllContexts is non-const, which recursively means
that External's Visit... functions must take non-const Decl*.  Which required
compilerplugins/clang/sharedvisitor/analyzer.cxx to be generalized to support
such Visit... functions with non-const Decl* parameters.)

Change-Id: Ia215291402bf850d43defdab3cff4db5b270d1bd
Reviewed-on: https://gerrit.libreoffice.org/83001
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-17 00:28:17 +01:00
Noel Grandin
5b374877b5 loplugin:singlevalfields
Change-Id: I31fd6b251dee9d1ee1a9ac59964034d0136e1f3e
Reviewed-on: https://gerrit.libreoffice.org/82978
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-16 20:19:54 +01:00
Stephan Bergmann
24b69e95c6 Improve loplugin:redundantpreprocessor performance a bit
...and add a minimal test for it

Change-Id: Ia6c61e41a7e60fd01c639e893c34bd9d215c1513
Reviewed-on: https://gerrit.libreoffice.org/82983
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-16 16:55:36 +01:00
Stephan Bergmann
ab8fc2603c Fix loplugin::Entry ODR violation
(caused crashes with CLANGDEBUG=1 in compilerplugins/Makefile-clang.mk)

Change-Id: I43ba276f03c87c97b624a59f2b368422fd5b0a7b
Reviewed-on: https://gerrit.libreoffice.org/82982
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-16 16:48:33 +01:00
Noel Grandin
03feda2465 loplugin:unusedfields
Change-Id: I021cd75685a091c1afd3ff3c144def6f9a784bee
Reviewed-on: https://gerrit.libreoffice.org/82972
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-16 12:27:59 +01:00
Stephan Bergmann
d04eef8582 loplugin:external: Don't warn for injected friend functions
Change-Id: I35c0930f6ab8ae5d96e433958cf29791c78d5e31
Reviewed-on: https://gerrit.libreoffice.org/82802
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-15 23:29:41 +01:00
Stephan Bergmann
565bcfbdcb Fix loplugin:fakebool for Objective C
...ignoring uses of "BOOL" in Objective C for now

Change-Id: I3eb48dc8d2592285f03f75dc7bc1b21e2383644d
Reviewed-on: https://gerrit.libreoffice.org/82803
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-15 19:15:47 +01:00
Stephan Bergmann
f213092d5a loplugin:external: Extend comment about the perils of moving a function
...into an unnamed namespace.  (And make it into a "leading comment" that
precedes the code it appeartains to.  It had orignally been meant as a "trailing
comment" that follows the code it appeartains to, and had been idented further
to indicate that, but clang-format unhelpfully breaks such indentation of
trailing comments that need to be preceded by a line break due to line length
limitations.)

Change-Id: I6a71a6b8e11ba641acfb542142fe14b4b6445f51
Reviewed-on: https://gerrit.libreoffice.org/82792
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-15 18:26:25 +01:00
Stephan Bergmann
ef57b9cd3c loplugin:external: Note all other declarations of the same entity
...not just those that came before

Change-Id: Ib10ca34cb2ee63124999d56bb00d94f000f33ea1
Reviewed-on: https://gerrit.libreoffice.org/82782
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-15 17:55:00 +01:00
Stephan Bergmann
82e1697d29 Fix loplugin:consttobool for assert on macOS
...which internally uses __builtin_expect and thus caused

> core/include/com/sun/star/uno/Any.hxx:750:13: error: implicit conversion of constant 1 of type 'long' to 'bool'; use 'true' instead [loplugin:consttobool]
>             assert(false); // this cannot happen
>             ^~~~~~~~~~~~~
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/assert.h:93:6: note: expanded from macro 'assert'
>     (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #e) : (void)0)
>      ^~~~~~~~~~~~~~~~~~~~~~~~~

(See 216bcceee1 "Special handling of
__builtin_expect in boolean expressions" for a similar fix in
loplugin:literaltoboolconversion.)

Change-Id: I4cf4b21006176c908995f5753dd0a38165383d87
Reviewed-on: https://gerrit.libreoffice.org/82773
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-15 14:38:27 +01:00
Stephan Bergmann
2a1533b019 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>
2019-11-15 14:09:03 +01:00
Stephan Bergmann
e21f5796b1 Silence -Werror,-Wsometimes-uninitialized
Change-Id: I491566c9f1fbbaabf9b050150b1567c5354227d0
Reviewed-on: https://gerrit.libreoffice.org/82752
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-15 12:49:05 +01:00
Stephan Bergmann
1205a4b774 New loplugin:consttobool
...to: "Find implicit conversions from non-'bool' constants (e.g., 'sal_False')
to 'bool'".

Due to how FALSE is defined as just

  #define FALSE (0)

(i.e., a literal of type 'int') but TRUE is defined as

  #define TRUE (!FALSE)

(i.e., an implicit conversion from 'int' to 'bool') in GLib (see the comment in
ConstToBool::VisitImplicitCastExpr), we get more warnings about uses of 'TRUE'
than of 'FALSE'.  For example, in libreofficekit/source/gtk/lokdocview.cxx there
is a warning about the 'TRUE' in

  g_main_context_iteration(nullptr, TRUE);

but not about the 'FALSE' in

  g_main_context_iteration(nullptr, FALSE);

(where the parameter of 'g_main_context_iteration' is of type 'gboolean').  Lets
live with that asymmetry for now...

(Besides the issues addressed directly in this commit, it also found the two
bogus asserts at 7e09d08807 "Fix useless
assert(true) (which would never fire)" and
122a0be8ae "Fix useless assert(true) (which would
never fire)", plus 5f0d6df7f5 "Use two-argument
form of static_assert".)

Change-Id: Id77322de9f94b85a7b65608a03e0e9865d14467b
Reviewed-on: https://gerrit.libreoffice.org/82667
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-14 19:53:53 +01:00
Stephan Bergmann
281d493fd9 Improve error message
(When temporarily taking a plugin out of the shared plugin by modifying its
leading

> #ifndef LO_CLANG_SHARED_PLUGINS

line I often forget about a trailing

> #endif // LO_CLANG_SHARED_PLUGINS

line, which then caused a hard to understand

> [GEN] compilerplugins/clang/sharedvisitor/sharedvisitor.cxx
> Incorrect version ''

failure.  This way, at least somehow mention the name of the problematic plugin
to give a bit of a clue.)

Change-Id: I9a9178ba0d7a32f448e91076376989f088ea70f8
Reviewed-on: https://gerrit.libreoffice.org/82657
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-14 13:29:05 +01:00
Stephan Bergmann
913d34ec6b Extend loplugin:salbool to loplugin:fakebool
...checking for unnecessary uses of more "fake bool" types.

In the past, some of the checks involving the types of variables or data
members, or the return types of functions, issued warnings that required
surrounding code to be changed too (e.g., when changing the signature of a
function whose address was taken).  These checks have been tightened now to not
warn in such cases (which avoids warnings that require changes to additional
code, or changes that might even be impossible to make, at the cost of being
less aggressive about removing all unnecessary uses of those "fake bool" types).

Change-Id: I70eb75039817cda34ed611387ee27dc5f36a3e2e
Reviewed-on: https://gerrit.libreoffice.org/82554
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-13 15:06:42 +01:00
Stephan Bergmann
bc6e282bc2 Clarify loplugin:external behavior for const(expr) vars
Change-Id: I4a649f9c9ed2015ed9b32a153060df9770b20403
Reviewed-on: https://gerrit.libreoffice.org/82493
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-12 13:04:28 +01:00
Stephan Bergmann
a0c30af2ac Make base of loplugin::FunctionAddress more flexible
(I'm planning to use it for a FilteringRewritePlugin.)

And while at it, base its current uses on FilteringPlugin.

Change-Id: I0acdcc6cb0b3a434b425405c8c438dbf65e4d3cb
Reviewed-on: https://gerrit.libreoffice.org/82451
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-11 17:29:06 +01:00
Stephan Bergmann
1b66d0141c Use more efficient NamedDecl::getName
Change-Id: I764b254180809c7ee020d5115e4b9e50e0227c09
Reviewed-on: https://gerrit.libreoffice.org/82321
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-08 21:22:29 +01:00
Caolán McNamara
72fad7a18d remove some unused getters
Change-Id: Iaa556491add4a7674f90ecfbf8e44f0b1d6583ee
Reviewed-on: https://gerrit.libreoffice.org/82198
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
2019-11-07 13:58:43 +01:00
Caolán McNamara
2b635e6de8 drop unused TreeView::set_top_entry
Change-Id: I70171b95baf29486c253e7d388ba59385da1d929
Reviewed-on: https://gerrit.libreoffice.org/82196
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
2019-11-07 13:09:57 +01:00
Noel Grandin
162f852836 loplugin:unusedmethods
Change-Id: I65354c7476dfaede1a607441d7c1b0c7ad038df4
Reviewed-on: https://gerrit.libreoffice.org/82186
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-07 09:01:00 +01:00
Noel Grandin
ef77870b1c loplugin:unusedfields
Change-Id: Ic1c0a2144f39373f93384bccbfc74356cac65ba0
Reviewed-on: https://gerrit.libreoffice.org/82185
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-07 08:06:27 +01:00
Noel Grandin
d81f90dda7 loplugin:unnecessaryvirtual
Change-Id: Ibffbd0f5d30ec14cace3638b2bb47c91a583711c
Reviewed-on: https://gerrit.libreoffice.org/82171
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-06 20:03:32 +01:00
Noel Grandin
9e087d4a30 loplugin:unusedvariablecheck tweak to find more stuff
but leave the tweak commented out, since it generates false positives

Change-Id: Iaf3f92414d2618f8780561f98765e33e282afe0c
Reviewed-on: https://gerrit.libreoffice.org/82121
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-06 10:47:15 +01:00
Noel Grandin
7b99cdb2d7 loplugin:indentation find broken if statements
so I don't read the "then" block as being a sequential statements

Change-Id: Ib2004acd3518bd4ebd2246f02a26c2c0a8bbab4c
Reviewed-on: https://gerrit.libreoffice.org/82069
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-06 06:27:51 +01:00
Stephan Bergmann
75bbbfc6bd loplugin:redundantcast: Don't warn about cast from nullptr_t to function ptr
See comments at <https://gerrit.libreoffice.org/#/c/81958/> "Only initialize
function pointer once" for a case where such a false warning caused trouble (in
a lambda with deduced return type and multiple return statements).

Change-Id: I64b0b8c45bd3d2a6075e336c361ec778fa0da481
Reviewed-on: https://gerrit.libreoffice.org/82034
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-04 17:20:28 +01:00