330 Commits

Author SHA1 Message Date
Noel Grandin
6e4a2540d4 new loplugin:noexceptmove
idea from mike kaganski

look for places where we can mark move operators as noexcept, which
makes some STL operations more efficient

Change-Id: Id732b89d1fcadd5ceb0ea2b9d159fed06136330f
Reviewed-on: https://gerrit.libreoffice.org/78251
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-08-30 08:12:07 +02:00
Stephan Bergmann
5f3c2204eb New loplugin:stdfunction
...finding dubious additions to namespace std (concentrating on functions for
now).  C++17 [namespace.std]/1: "The behavior of a C ++ program is undefined if
it adds declarations or definitions to namespace std or to a namespace within
namespace std unless otherwise specified."

This found

ad4c7b97752b4da73808402604d6f96b39d920f5 "Avoid declaring function templates in
 namespace std"
042e30a3dc057aef4a02d95960e4dd4fb8d083ae "Avoid adding a function template
 declaration to namespace std"
cae9240a76cdb0eeed92421930d3b4cbef0ac201 "Avoid adding a function declaration to
 namespace std"

Change-Id: Ic2ba54e2a8bf931d5c58cedf499c0d1229eb2166
Reviewed-on: https://gerrit.libreoffice.org/78220
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-08-28 12:47:21 +02:00
Noel Grandin
9e0b3423f2 loplugin:referencecasting find more redundant static_cast
Change-Id: I3a51812bbd3fcdc6b11e47cb12962f0d4fa7a2ae
Reviewed-on: https://gerrit.libreoffice.org/78191
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-08-27 18:42:13 +02:00
Noel Grandin
4ad54c3471 new loplugin:returnconstval
look for code that thwarts copy-elision/move optimisations by
returning const values.

Change-Id: Iafa038d15051e06ee76d8a1c0ce8b7d234cd8488
Reviewed-on: https://gerrit.libreoffice.org/77964
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-08-23 09:12:16 +02:00
Noel Grandin
10280dabe2 loplugin:constvars, look for loop vars that can be const
Change-Id: I67ee714739800f3718f9d3facf57474cd564d855
Reviewed-on: https://gerrit.libreoffice.org/77415
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-08-21 11:16:15 +02:00
Stephan Bergmann
e380e35348 Adapt loplugin:nullptr to RecursiveASTVisitior::TraverseInitListExpr change
...<https://github.com/llvm/llvm-project/commit/
0a42fe70a566f22599e04a6f1344ca2dc5565e17> "[AST] Treat semantic form of
InitListExpr as implicit code in traversals"

Change-Id: Ifd17009fcc6933abf0e9178dbe47fb9c14b274b7
Reviewed-on: https://gerrit.libreoffice.org/77595
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-08-16 19:54:25 +02:00
Noel Grandin
7d7a7862a7 new loplugin:sequenceloop
look for places we should be using std::as_const on for-range
loops over uno::Sequence, to avoid triggering a copy

Change-Id: I7efb641bf09d37c87946f03428ee4eec90298c8a
Reviewed-on: https://gerrit.libreoffice.org/77441
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-08-16 09:04:51 +02:00
Stephan Bergmann
ed115c1bb7 missing include
Change-Id: I9c3d551d2053b53bde3b032036bc531a02217300
Reviewed-on: https://gerrit.libreoffice.org/76782
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-08-01 14:40:46 +02:00
Noel Grandin
12062cb281 new loplugin:mapindex
Change-Id: I6b5f73b2187009e95d4d666e03e5803f522cee06
Reviewed-on: https://gerrit.libreoffice.org/76584
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-08-01 09:09:34 +02:00
Stephan Bergmann
6b962889b2 Improved loplugin:stringconstant (now that GCC 7 supports it)
Change-Id: I8f83c1941b8f39b261005939f4dcf3577ae9fc6f
Reviewed-on: https://gerrit.libreoffice.org/76702
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-07-31 16:29:45 +02:00
Noel Grandin
c4bce5dafd resurrect and improve loplugin:referencecasting
Improve the plugin to avoid generating false+ with the special case of
querying XInterface (what the code calls normalisation).

Also ignore places where the querying is dealing with ambiguous base
classes.

Change-Id: I23b2b2fa6618328fafc4707b94c26582a462ea87
Reviewed-on: https://gerrit.libreoffice.org/74993
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-07-23 13:51:18 +02:00
Noel Grandin
9fbedb7929 improve loplugin:blockblock
look for nested blocks where the inner block also contains a break
statement.

Change-Id: I1e5b6ca4c42b995c9479a68b34a1e2f1eb015f57
Reviewed-on: https://gerrit.libreoffice.org/74946
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-07-01 10:23:53 +02:00
Noel Grandin
4583911575 improve loplugin:simplifyconstruct
Change-Id: If863d28c6db470faa0d22273020888d4219e069e
Reviewed-on: https://gerrit.libreoffice.org/74559
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-06-25 13:53:21 +02:00
Noel Grandin
8303e7ed66 loplugin:unusedfields improvements
tighten up the only calling write-only methods part of the analysis

Change-Id: I5bc6fdf0ce51940653317e8a48c5241705c90d4c
Reviewed-on: https://gerrit.libreoffice.org/74022
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-06-14 11:37:35 +02:00
Noel Grandin
b6086804af new loplugin logexceptionnicely
to be used to find places to use new TOOLS_WARN_EXCEPTION,etc macros

Change-Id: I213ab47efa82075435bb800736ee0937aea0486c
Reviewed-on: https://gerrit.libreoffice.org/73950
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-06-13 13:39:08 +02:00
Noel Grandin
e02b9ccf58 revert part of "improve loplugin:stringconstant"
Revert part of
    commit dd8d5e5795358d732a9f7a8af7c35f662321e332
    Date:   Mon Apr 29 11:18:21 2019 +0200
    improve loplugin:stringconstant

sberg's original gerrit comment:
but there can also be other problematic overloads for parameters like
`void const *` or `std::string_view`.  I'm not sure this change is worth
the potential false positives.

and continuing IRC discussion:
<noelgrandin> I'll revert the compilerplugins/ part
<sberg> noelgrandin, my main concern is that /if/ somebody eventually
runs into such an overload situation, it's really hard to get the
warnings/errors fixed for those people, short of going into the plugin
itself

Change-Id: I4916ce8943c4319d7ef9084e22d6a0eeb430b15c
2019-04-30 09:28:40 +02:00
Noel Grandin
dd8d5e5795 improve loplugin:stringconstant
to find more places we can elide the OUString() constructor at call
sites

Change-Id: Ie09f3c61f2c4b4959c97dc98ebcbaf7c51d5d713
Reviewed-on: https://gerrit.libreoffice.org/71514
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-04-30 08:43:51 +02:00
Noel Grandin
bd44b3eef6 tdf#89522 PERF FILEOPEN xlsx, part 1
Inherit from tools::WeakBase non-virtually, so that we can use a
static_cast in tools::WeakReference::get instead of a dynamic_cast.

This takes the file-open time from 1m21 to 40s for me.

Add a clang plugin to make sure we don't accidentally end up inheriting
from tools::WeakBase more than once.

Change-Id: I9c7c36403333f99094e1f9d8cce2ecd9200377f9
Reviewed-on: https://gerrit.libreoffice.org/71231
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-04-24 16:09:08 +02:00
Stephan Bergmann
05a0c51ced New loplugin:selfinit
...to find more bugs like the one addressed in
6340daac7b99c65249363a4bb61c492de31ef5d6 "Revert broken
loplugin:sequentialassign change".  What it does is:  "Warn when a variable is
referenced from its own initializer.  This is not invalid in general (see C++17
[basic.life]), but is at least suspicious."  It found one false positive
(addressed with 884ad0d1af88f9985d30ef0dfe92d89e82f8e576 "Split
localProcessFactory function into class with setter and getter") and five true
positives (addressed with e0ccbe72ed6eb0d309ed272a78fd67a512acff5d "Fix use of
variable before its lifetime begins" and
0e335af4d3f044511551fa2ede20911beaee9b41 "Fix uses of variables before their
lifetimes begin").

Change-Id: I4c45cceaa042e93b37ad24a54784c027f6ca1f87
Reviewed-on: https://gerrit.libreoffice.org/70897
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-04-17 21:59:53 +02:00
Noel Grandin
b52f309f2b improve loplugin simplifyconstruct
to find stuff like
   OUString s = OUString("xxx")

Change-Id: Ie7ed074c1ae012734c67a2a89c564c1900a4ab04
Reviewed-on: https://gerrit.libreoffice.org/70697
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-04-15 08:37:54 +02:00
Noel Grandin
b65f3fbb2b new loplugin sequentialassign
Look for places we are assigning to the same variable twice
in succession, which means we can simplify that to a single assign

Change-Id: I499d20e28f5595e81e927bef8e1bf364eea8ba91
Reviewed-on: https://gerrit.libreoffice.org/70531
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-04-11 08:52:49 +02:00
Stephan Bergmann
88b076c459 Adapt to Windows sal_uIntPtr/sal_uLong typedefs
Change-Id: Ic6f269f75e2b64e0c2a53455e9ee4ccf9891cfb0
Reviewed-on: https://gerrit.libreoffice.org/69807
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-03-27 14:17:39 +01:00
Stephan Bergmann
be0655364c Improve loplugin:typedefparam error reporting
Change-Id: I2ed4c20ab909b79fca794fb04259018fbfcb1db5
Reviewed-on: https://gerrit.libreoffice.org/69787
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-03-27 10:57:46 +01:00
Noel Grandin
b1cfdb7bee new loplugin:unoquery
look for places we are doing code like:

    Reference<XProperty>(model, css::uno::UNO_QUERY)->getAsProperty()

which might result in a SIGSEGV is the query fails

Change-Id: I5cbdbc9e64bd0bed588297c512bf60cbacb9442e
Reviewed-on: https://gerrit.libreoffice.org/69044
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-03-25 07:19:13 +01:00
Noel Grandin
5c23459245 new loplugin constvars
detect static variables that can be made const.

Thanks to mike kaganski for suggesting this.

Here I introduce a new plugin feature - using markers
in nearby comments to disable the plugin for specific
vars.

Some of this stuff was old debugging code. I removed the stuff
that was older than 5 years.

Change-Id: I6ec7742a7fdadf28fd128b592fcdf6da8257585c
Reviewed-on: https://gerrit.libreoffice.org/68807
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-03-08 07:20:29 +01:00
Noel Grandin
cfd080d00a loplugin:staticconstfield improve warning message
Change-Id: I000dff6b1b6e33e1b2c5aa337c027c1edd7b1003
Reviewed-on: https://gerrit.libreoffice.org/68795
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-03-06 11:06:22 +01:00
Noel Grandin
a2e3705d8b loplugin:unnecessaryparen improve member expression
Change-Id: I304621018cb1e2a47e478e86df4229bcf2176741
Reviewed-on: https://gerrit.libreoffice.org/68757
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-03-06 06:47:06 +01:00
Noel Grandin
191f85df58 re-land "new loplugin typedefparam""
This reverts commit c9bb48386bad7d2a40e6958883328145ae439cad,
and adds a bunch more fixes.

Change-Id: Ib584d302a73125528eba85fa1e722cb6fc41538a
Reviewed-on: https://gerrit.libreoffice.org/68680
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-03-05 12:12:26 +01:00
Noel Grandin
c9bb48386b Revert "new loplugin typedefparam"
This reverts commit 9865440d217d975206a3f91612f0666312bc8fd8.

This is not ready to land yet, seems like the latest update
of the logic reveals a bunch more places I need to fix before it can land.
2019-03-04 08:56:11 +02:00
Noel Grandin
9865440d21 new loplugin typedefparam
verify that parameters use the exact same typedef-names (if any)
in definition and declaration

Change-Id: I55d2817f599b0253904dce2d35a1a93967e15a77
Reviewed-on: https://gerrit.libreoffice.org/68439
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-03-04 07:32:43 +01:00
Noel Grandin
48dc1e48d0 loplugin:unnecessaryoverride look for more patterns
like
   bool Foo::bar() {
       b = Super::bar();
       return b;
   }

Change-Id: I5e4c8005a3da7d7487c9039c35dcbb1d17e65bd7
Reviewed-on: https://gerrit.libreoffice.org/68418
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-02-27 09:13:25 +01:00
Noel Grandin
57ac2fcdda loplugin:unusedfields fix read/write when dealing with r<<= and >>=
Change-Id: I103bcc2f21741d0a52a0bdf053fdbddf5a3e9ea0
Reviewed-on: https://gerrit.libreoffice.org/68387
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-02-27 07:36:12 +01:00
Noel Grandin
4d502ef355 loplugin:simplifybool improve search for negated operator
Change-Id: Id6ac35fefa5c3e1f64c222713791e849b3cb4d34
Reviewed-on: https://gerrit.libreoffice.org/68379
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-02-27 07:35:11 +01:00
Andrea Gelmini
e99a7a8dfa Fix typo
Change-Id: I428b4c484ba6e18ee2947c9be4688317764769f2
Reviewed-on: https://gerrit.libreoffice.org/68240
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2019-02-23 14:19:19 +01:00
Stephan Bergmann
b87f3dc3c5 loplugin:writeonlyvars is no-op on Windows, so don't run its test there
But nevertheless, make sure that the variables m_bar9/10 used in combination
with css::uno::Any have UNO-compatible type.

Change-Id: I4e9915193386278ace128df94f7722d90b2567f2
Reviewed-on: https://gerrit.libreoffice.org/68195
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-02-22 13:35:22 +01:00
Noel Grandin
5febdea1d1 loplugin:unusedfields improve write-only when dealing with operators
Change-Id: I3a060d94de7c3d77a54e7f7f87bef88458ab5161
Reviewed-on: https://gerrit.libreoffice.org/68132
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-02-21 12:04:28 +01:00
Stephan Bergmann
0626e66d76 Avoid loplugin:indentation after preproc conditional inclusion lines
...to not trigger (for --disable-dbgutil) at

>                         rContentAtPos.eContentAtPos = IsAttrAtPos::TableBoxFml;
> #ifdef DBG_UTIL
>                         if( RES_BOXATR_VALUE == pItem->Which() )
>                             rContentAtPos.eContentAtPos = IsAttrAtPos::TableBoxValue;
>                         else
> #endif
>                             const_cast<SwTableBoxFormula*>(static_cast<const SwTableBoxFormula*>(pItem))->PtrToBoxNm( &pTableNd->GetTable() );

(sw/source/core/crsr/crstrvl.cxx:1710)

Change-Id: I8fd5c8a1cd40450bdd8cc97057e5233a0134f044
Reviewed-on: https://gerrit.libreoffice.org/68030
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-02-20 11:14:55 +01:00
Stephan Bergmann
893ee43180 Tell about presumed corresponding negated operator
Change-Id: Ic7ed64ecc4902853dc7431294484abb74e8da65b
Reviewed-on: https://gerrit.libreoffice.org/67953
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-02-18 10:22:48 +01:00
Noel Grandin
aa51774e6a loplugin:simplifybool, check for !(!a op !b)
Change-Id: Ic3ee9c05705817580633506498f848aac3ab7ba6
Reviewed-on: https://gerrit.libreoffice.org/67866
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-02-18 07:15:57 +01:00
Noel Grandin
e132e781d8 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>
2019-02-15 11:52:41 +01:00
Stephan Bergmann
bf1a511f9c Make loplugin:stringconcat more robust
Change-Id: Ib8adefd90141007c0422b4c15ba9c2cc5f707f3f
Reviewed-on: https://gerrit.libreoffice.org/67762
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-02-13 13:56:12 +01:00
Noel Grandin
0d1253c232 new loplugin writeonlyvars
largely based on the relevant portion of the unusedfields loplugin, but
adapted for local vars

Change-Id: Ic522a941573940e8f75c88f90ba5f37508ca49b1
Reviewed-on: https://gerrit.libreoffice.org/66835
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-02-11 13:25:31 +01:00
Noel Grandin
f76bf262a6 new loplugin indentation
look for mixed indentation in compound statements, which makes them hard
to read, and sometimes makes it look like a statement is associated with
a nearby if/for

Change-Id: Ic8429cee1f9a86d938097a4a8769a2bce97b3361
Reviewed-on: https://gerrit.libreoffice.org/63283
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-02-11 08:24:19 +01:00
Stephan Bergmann
8949f98d16 loplugin:unusedfileds is no-op on Windows, so don't run its test there
But nevertheless, make sure that the variables m_bar9/10 used in combination
with css::uno::Any have UNO-compatible type.

Change-Id: I241d8b5d37de60b00b5bfdc69e642872b28e8ee2
Reviewed-on: https://gerrit.libreoffice.org/67201
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-01-31 14:13:22 +01:00
Noel Grandin
a6358f1c1b improve loplugin constparams
Change-Id: Ic1833dbd030044011e7ee5f89dc35737e5469f05
Reviewed-on: https://gerrit.libreoffice.org/66586
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-01-25 07:58:04 +01:00
Noel Grandin
924da47e03 update useunique_ptr loplugin
with more exclusions

Change-Id: I95e7376ecf9c479d05b85c71f863d9ba40417538
Reviewed-on: https://gerrit.libreoffice.org/66552
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-01-18 07:51:04 +01:00
Noel Grandin
61dfcdda88 loplugin:unusedfields improve write-only logic
when dealing with modifications to container classes (e.g. std::vector)

Change-Id: Ic30043631007355ee9a3d9e3f9b6488b435182d6
Reviewed-on: https://gerrit.libreoffice.org/65050
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-12-13 08:37:58 +01:00
Julien Nabet
88738347f8 cppcheck: incorrectStringBooleanError
Change-Id: I7f4bce8444c6c022d856d20b06de4a4834148ea2
Reviewed-on: https://gerrit.libreoffice.org/64834
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Julien Nabet <serval2412@yahoo.fr>
2018-12-10 11:46:41 +01:00
Stephan Bergmann
ab9b67bbb0 Remove obsolete SAL_FALLTHROUGH completely
...after 7ffdd830d5fb52f2ca25aa80277d22ea6d89970b
"HAVE_CPP_ATTRIBUTE_FALLTHROUGH is always true now"

Change-Id: I54e5ff4e036a6bb3e5774d1c0524158aae18e937
Reviewed-on: https://gerrit.libreoffice.org/64800
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2018-12-08 13:28:16 +01:00
Noel Grandin
e4472d3c13 loplugin:unnecessaryparen include more assignments
Change-Id: I9fb8366634b31230b732dd38a98f800075529714
Reviewed-on: https://gerrit.libreoffice.org/64510
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-12-05 07:49:30 +01:00