99 Commits

Author SHA1 Message Date
Noel Grandin
d3971ec256 new loplugin:blockblock
Change-Id: I7b68b70fa4c7234e8882f7627026959a596968fd
Reviewed-on: https://gerrit.libreoffice.org/43025
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-10-03 08:41:11 +02:00
Stephan Bergmann
2e8a95d1f8 loplugin:constparams: Ignore functions whose address is taken
(unless as the callee of a function call).  In response to
<https://gerrit.libreoffice.org/#/c/42912/> "DO NOT MERGE - error in clang
static plugin".  Many of the whitelisted functions can now be taken off the
list.

Change-Id: I04c2ee445e7973a288f42fd663d8b2d78cd3c5aa
Reviewed-on: https://gerrit.libreoffice.org/42958
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
2017-09-30 15:02:22 +02:00
Stephan Bergmann
62274b24f9 Suppress loplugin:flatten in functions involving preprocessing conditionals
...as needed by clang-cl on Windows to avoid unhelpful warnings about
OleEmbeddedObject::changeState (embeddedobj/source/msole/oleembed.cxx)
containging an "if" in an "#ifdef _WIN32" block followed by "else throw".

Change-Id: I95bed29b9003db08499156ae7f885aeeea5a0158
Reviewed-on: https://gerrit.libreoffice.org/42963
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2017-09-30 13:28:43 +02:00
Noel Grandin
1ffba0e356 loplugin:flatten check for throw in then clause
also make the plugin ignore the case where we have var decl's in the
clause we want to flatten, which could lead to problematic extension of
variable lifetime

Change-Id: I3061f7104e8c6a460bf74f5eac325a516ec50c59
Reviewed-on: https://gerrit.libreoffice.org/42889
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-09-29 08:51:48 +02:00
Stephan Bergmann
c9f3277ea7 loplugin:stringconstant: Simplify construction of non-ASCII OUString
Change-Id: If80c53978106789824e6154db396baeecc1969dd
Reviewed-on: https://gerrit.libreoffice.org/42876
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
2017-09-28 08:27:11 +02:00
Stephan Bergmann
f79123a823 loplugin:stringconstant: Also handle u8"..." strings
(just in case)

Change-Id: Id8ce7436bacba874d9bc04915e42622e3cfca67a
2017-09-27 07:53:00 +02:00
Noel Grandin
ade2769232 improve unnecessarycatchthrow plugin
it is not legal to eliminate a catch/re-throw where the re-throw
expliciting mentions the exception variable and the exception variable
is a non-final class

Change-Id: I7fd88b0d004d2efa66aef2c0876e07f203da3c28
Reviewed-on: https://gerrit.libreoffice.org/42782
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-09-26 11:27:08 +02:00
Stephan Bergmann
d883e3556a loplugin:redundantcast: cstyle_cast within reinterpret_cast
Change-Id: Ie31c9dd6d8741aa856553b798bb5b7f695a3fe0f
Reviewed-on: https://gerrit.libreoffice.org/42776
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
2017-09-26 10:01:54 +02:00
Noel Grandin
2684aefcf5 new loplugin unnecessarycatchthrow
Change-Id: Iabab71ee076227bc38447ec109afaea1e53a86a6
Reviewed-on: https://gerrit.libreoffice.org/42643
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-09-23 09:01:46 +02:00
Stephan Bergmann
5c54b6523f loplugin:stringconstant: warn about explicit length mismatch
(just in case)

Change-Id: I9eaf6e920fc7fc3ebc8c705df1cdf34b325db74a
Reviewed-on: https://gerrit.libreoffice.org/42614
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2017-09-22 13:45:07 +02:00
Michael Stahl
0fbfdce3ea compilerplugins: add test for badstatics
Change-Id: Ibdb3144c0510ed723a01ca28d7cdcd6b21caec54
Reviewed-on: https://gerrit.libreoffice.org/42596
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
2017-09-22 10:59:42 +02:00
Stephan Bergmann
7b45044fd1 Also handle OUString with non-RTL_TEXTENCODING_ASCII_US encoding
(just in case)

Change-Id: I7ba2967c1cef81a3f6604077d876c8b993f7f16a
Reviewed-on: https://gerrit.libreoffice.org/42609
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2017-09-22 08:19:55 +02:00
Noel Grandin
e8b5ec6590 loplugin:unusedfields, fix var taking ref
Change-Id: I0ea1f0c7488c140fca9f64de326c6ac588ece925
2017-09-21 10:01:43 +02:00
Noel Grandin
dc97ede7cf new loplugin flatten
look for places where we can flatten the control flow in a method by
exiting early with a throw, ie. instead of

   if (cond)
       stuff();
   else
       throw ex;

we  change it to:

   if (!cond)
      throw ex;
   stuff();

Change-Id: I8b6bdf883b325807c7e3a3ef698e4f4606e7d38b
2017-09-20 12:42:33 +02:00
Noel Grandin
1ff0f0ba29 improve unusedfields loplugin
(*) IsPassedByNonConst was completely wrong, not even sure why it worked
before.
(*) treat a field passed to operator>>= as being written to, but not
read

Change-Id: Id3a5f2f35222986fe5edba3f5a58215a1815d401
2017-09-18 09:45:15 +02:00
Stephan Bergmann
7282b25f22 Fix loplugin:redundantcast's VisitCXXFunctionalCastExpr
...when t1 is ElaboratedType sugar (which isn't only used when the type is
written with an elaborated type keyword, but also when it is written with a
qualified name).

(I originally wrote testArithmeticTypedefs to track down a different issue,
which turned out to be a non-issue, with this fix as fall-out.  So that test
doesn't quite match the theme of this commit, but is a worthwhile addition
nonetheless.)

Change-Id: Ic447da4399853d7d045e3e2e7ade8ddf52d89749
2017-09-15 18:50:45 +02:00
Noel Grandin
5685ee25aa improve redundantcast loplugin
to find c-style casts where the expression is a templated method

Change-Id: Ifbd1e2cdc72d906fc95a7ec0f9408c3f6d2a836b
Reviewed-on: https://gerrit.libreoffice.org/42275
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-09-14 14:43:43 +02:00
Stephan Bergmann
7f3ca30951 Enable -Wunreachable-code
...motivated by <https://gerrit.libreoffice.org/#/c/41565/2> adding dead code
at the end of a switch statement, after the last case's "break".

-Wunreachable-code appears to work well on Clang, while it appears to have no
effect on GCC.

Most of the affected places are apparently temporary/TODO/FIXME cases of
disabling code via "if (false)", which can be written with an extra set of
parentheses as "if ((false))" to silence -Wunreachable-code on Clang (which thus
needed loplugin:unnecessaryparen to be adapted accordingly).  In some cases,
the controlling expression was more complex than just "false" and needed to be
rewritten by taking it out of the if statement to silence Clang.

One noteworthy case where the nature of the disabled code wasn't immediately
apparent:

  Sep 12 16:59:58 <sberg> quikee, is that "if (false)" in
   ScExponentialSmoothingDialog::ApplyOutput
   (sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx) some work-in-
   progress or dead code?
  Sep 12 17:02:03 <quikee> sberg: WIP, but you can remove it
  Sep 12 17:04:47 <sberg> quikee, I'll wrap the false in an extra set of
   parentheses for now, to silence -Wunreachable-code (I wouldn't want to
   remove it, as I have no idea whether I should then also remove the "Initial
   value" comment preceding it)
  Sep 12 17:07:29 <quikee> sberg: both are different ways to calculate the
   "intital value"... so no

Another case where the nature of the dead code, following while (true) loops
without breaks, is unclear is sd/source/ui/remotecontrol/BluetoothServer.cxx,
where I added TODO markers to the workarounds that silence the warnings for now.

basic/source/sbx/sbxvalue.cxx had a variable of type double, of automatic
storage duration, and without an initalizer at the top of a switch statement.
Clang warning about it is arguably a false positive.

Apart from that, this didn't find any cases of genuinely dead code in the
existing code base.

Change-Id: Ib00b822c8efec94278c048783d5997b8ba86a94c
Reviewed-on: https://gerrit.libreoffice.org/42217
Tested-by: Stephan Bergmann <sbergman@redhat.com>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2017-09-13 10:24:38 +02:00
Noel Grandin
dccd1633a1 loplugin:unnecessaryparen include case statements
Change-Id: I79fb3eec0d5d466e33b2e18621a7169695edf82f
Reviewed-on: https://gerrit.libreoffice.org/41920
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-09-06 08:43:33 +02:00
Noel Grandin
7aa7f4d9e4 loplugin:unnecessaryparen include c++ casts
Change-Id: I132d3c66f0562e2c37a02eaf4c168d06c2b473eb
Reviewed-on: https://gerrit.libreoffice.org/41874
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-09-04 10:52:41 +02:00
Noel Grandin
326295bf10 new loplugin:redundantpointerops
Change-Id: I8428d86ea9628d69c2b40b36feee3da428a9fe1d
Reviewed-on: https://gerrit.libreoffice.org/41787
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-09-04 08:44:19 +02:00
Noel Grandin
c66568d6b0 loplugin:useuniqueptr, look for containers..
that can use std::unique_ptr, and apply it in i18npool

Change-Id: Ib410abaf73d5f392c7a7a9a322872b08c948f9e9
Reviewed-on: https://gerrit.libreoffice.org/41438
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-08-23 18:35:00 +02:00
Stephan Bergmann
4eaaa812ce Adapt tests to Windows
Change-Id: I8d33234196060f96ad47c9d0fead4f31218f8bdd
2017-08-21 11:11:26 +02:00
Noel Grandin
256c28ae33 new loplugin:expressionalwayszero
The code in SvXMLExportItemMapper::exportXML was broken as far back as
its introduction in

    commit 0c28e3c480a95c03b513c55f029b979bcd9c0401
    "Move SvXMLAttrContainerItem to SVX, moved writer only code to sw"

Change-Id: I90043ce8b7263aa56fd0883d350e29b97eeaf99b
Reviewed-on: https://gerrit.libreoffice.org/41282
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-08-18 14:19:20 +02:00
Noel Grandin
d21b119df3 loplugin:passstuffbyref ignore params that are assigned to
makes writing nice code awkward sometimes.

Also split plugin into two different plugins, the logic was getting
tangled up.

Change-Id: I232e314d29c766c160c29373988dc37a466505be
2017-08-17 13:18:34 +02:00
Noel Grandin
b0d7b8fa63 new loplugin convertuintptr
an experiment to see if I can make the process of eliminating
sal_uIntPtr a little easier

Change-Id: I808185fbf18826cb9ab5612a7be4148d52045957
2017-08-17 13:18:34 +02:00
Noel Grandin
a4602c791f add sal_uLong to droplong loplugin
Change-Id: Ief92b4ee97f561613bc730a91c27fe192f485d77
2017-08-17 09:25:46 +02:00
Noel Grandin
9fb742489b move deadclass plugin to store
<sberg> noelgrandin, and is loplugin:deadclass even sound?

    struct B { B(B const &) {} }; struct D: B { D(): B(*this) {} };

Change-Id: Idadd379b925aa6f9de6c625bffa8560ec4192ac7
2017-08-16 13:17:07 +02:00
Noel Grandin
0c3bd1d482 new loplugin:droplong
The types 'long' and 'unsigned long' are different sizes on different
platforms, making them wholy unsuitable for portable code.
And when I mean different sizes, I mean 64bit Linux and 64bit Windows
have different bit sizes.

Change-Id: Id4d8cd709bf71a3f85ed6515fae2b0a21ae8c25d
Reviewed-on: https://gerrit.libreoffice.org/41130
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-08-14 09:14:39 +02:00
Noel Grandin
4d89865ef2 new loplugin:deadclass
look for classes which only have copy/move constructors, and so are
effectively dead

Change-Id: I0b844f301e2200c2b40031856bfdb0b0e2c8f77d
Reviewed-on: https://gerrit.libreoffice.org/41039
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-08-11 21:20:25 +02:00
Noel Grandin
c9253818ec loplugin:oncevar
extend oncevar to any POD type

Change-Id: Ia98ee0a67f183e40fb0c38477760124b2c411dc0
Reviewed-on: https://gerrit.libreoffice.org/40564
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-31 08:25:07 +02:00
Noel Grandin
b09deb0753 loplugin:constparams handle constructors
had to change the structure of the plugin considerably, was too messy to
structure it to do the calculations on a per-function basis

Change-Id: I4edee7735f726101105c607368124a08dba21086
Reviewed-on: https://gerrit.libreoffice.org/40516
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-28 14:51:56 +02:00
Noel Grandin
32878b6857 enhance unusedfields plugin to find readonly fields
Change-Id: I4da97443fc7eb14fd94959a026ab45a9256c055f
Reviewed-on: https://gerrit.libreoffice.org/40158
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-19 09:25:52 +02:00
Stephan Bergmann
e27f2a8720 Fix test for clang-cl
...whatever it is that causes clang-cl to not analyze the template code
otherwise

Change-Id: Id4da996714fe93c454abb3669a12d8afe27b918b
2017-07-17 17:17:27 +02:00
Noel Grandin
8e39ef6692 extend loplugin useuniqueptr to POD types
Change-Id: I6ff24f048bd8f75bf87a78b718f37b57855d4781
Reviewed-on: https://gerrit.libreoffice.org/39932
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-14 10:13:46 +02:00
Noel Grandin
51a50cc95a improve useuniqueptr loplugin to find arrays
Change-Id: I81e9d0cd4f430b11d20037054055683240792240
Reviewed-on: https://gerrit.libreoffice.org/39825
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-13 11:56:05 +02:00
Stephan Bergmann
4e451cad21 loplugin:oncevar for value-dependent constant expressions
(Where the change to basic/source/comp/codegen.cxx reveals that
loplugin:loopvartoosmall also needs the Clang < 3.9 workaround from
33ee8e61292af05627f5f72ea2f93ad80e715e46 "Work around bug in Clang 3.8".)

Change-Id: I9f23b9648bc11ca4136a0fbdd332570ba70ee77c
Reviewed-on: https://gerrit.libreoffice.org/39667
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2017-07-13 10:37:53 +02:00
Noel Grandin
4250b25c6a teach unnecessaryparen loplugin about identifiers
Change-Id: I5710b51e53779c222cec0bf08cd34bda330fec4b
Reviewed-on: https://gerrit.libreoffice.org/39737
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-10 09:57:24 +02:00
Noel Grandin
868d8c8f0f loplugin:unnecessaryparen handle parens inside call expr
stick to single-arg function calls, sometimes parens in multi-arg calls
might be there for clarity

Change-Id: Ib80190c571ce65b5d219a88056687042de749e74
Reviewed-on: https://gerrit.libreoffice.org/39676
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-07 10:45:05 +02:00
Noel Grandin
4f7b2ca221 loplugin:unusedfields in sc
found a couple more by running
    make build-nocheck
to exclude testing code

Also, teach unusedfields loplugin about operator<<, since
referring to a field in an ostream operator<< does not indicate a
real use, it's normally for debugging

Change-Id: I3dce22bf5afda2fd09e01de9bf1d0ef85e535aa8
Reviewed-on: https://gerrit.libreoffice.org/39625
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-06 13:00:56 +02:00
Noel Grandin
13341ffa49 teach unnecessaryparen plugin about other kinds of statements
i.e. do / while / switch

Change-Id: Id0985015cc425557f9984734701d56466f8a6088
Reviewed-on: https://gerrit.libreoffice.org/39601
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-06 08:31:52 +02:00
Noel Grandin
4b2262ab5b new loplugin unnecessaryparen
Change-Id: Ic883a07b30069ca6342d7521c8ad890f4326f0ec
Reviewed-on: https://gerrit.libreoffice.org/39549
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-07-05 11:08:48 +02:00
Stephan Bergmann
65d6c64259 loplugin:casttovoid
Change-Id: I427b15b35ef6e7c803cb8a00c961d35175ae8cb2
2017-07-03 12:34:38 +02:00
Noel Grandin
979d58c9a9 loplugin:unusedfields in toolkit..xmloff
Change-Id: I4964ff97e0a1735dc08c6ad204cae0b08e9ffc2c
Reviewed-on: https://gerrit.libreoffice.org/39406
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-06-30 19:50:30 +02:00
Stephan Bergmann
09031ef2fe Avoid getQualifiedNameAsString
Change-Id: I448bfd63f1a2fb9cac3366146b10ff6a465e6db7
2017-06-30 11:16:03 +02:00
Noel Grandin
4cc2fc6cef unusedfields loplugin writeonly analysis improvements
(1) ignore reads inside copy/move constructors/operator=
(2) fix false+ when assigning to array field
(3) ignore reference ("&") fields

Change-Id: I69a1a1c567a0b28a783e605982e5150811b6cc4a
2017-06-29 11:00:57 +02:00
Noel Grandin
497e40ad03 improve refcounting loplugin
to find ref-counted classes being managed via other smart pointer
classes.
Hopefully prevent needing fixes like
642ae256ea5b8083ba0b3c097ca8ea52304b9cdb
"ChangedUIEventListener is refcounted, mustn't be helt by unique_ptr"

Change-Id: I6b0c5f8f87ce3546a8a1104ce1000470c09459bd
Reviewed-on: https://gerrit.libreoffice.org/39378
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-06-29 09:35:30 +02:00
Noel Grandin
71112060e0 loplugin:oncevar various
Change-Id: I8b82d46d4688b1a59d6fe1b05da7d5c8dfc13ca6
Reviewed-on: https://gerrit.libreoffice.org/38766
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-06-29 08:18:35 +02:00
Noel Grandin
03ee996717 loplugin:unusedfields fix more false +
deal with fields assigned to local variables, and some general cleanup

Change-Id: I894c74a01e9e28935ecd84308c2e92b080afafc6
2017-06-20 10:02:32 +02:00
Noel Grandin
9d9d024ffb loplugin:unusedfields fix some more false positives
in the write-only analysis

Change-Id: Ic570416e855b8ec38d54f6f6f1adef4819ea53ee
2017-06-20 10:01:48 +02:00