1066 Commits

Author SHA1 Message Date
Noel Grandin
3b60f59bc5 loplugin:unusedfields fix false positive
When the field in question is read from inside a constructor
initializer.

In the process, create some needed infrastructure in the plugin classes.

Change-Id: I2f440efa6912801a236727c9fe3180404616958c
Reviewed-on: https://gerrit.libreoffice.org/38960
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-06-20 07:49:27 +02:00
Noel Grandin
45c06838e9 only unit-test one loplugin at a time
tell the plugin code when we are unit-testing it, so we can suppress all
the warnings except for the plugin we are currently testing

Change-Id: I240c8e37eba90c219e53c29531a3a43bc841a1c8
2017-06-19 11:34:15 +02:00
Stephan Bergmann
1e3a00f0c7 Make SfxItemSet ranges correct by construction: Fix static cases
...with the aid of an extended compilerplugins/clang/store/sfxitemsetrewrite.cxx
(which in turn needed a small addition to compilerplugins/clang/check.hxx).

Enable svl::detail::validGap check for the static case, but keep it disabled for
now for the dynamic case.

Change-Id: I4846ba8e99aff94a86518e2cb5044e575093386e
2017-06-19 09:38:05 +02:00
Stephan Bergmann
13bb5a4b09 Make SfxItemSet ranges correct by construction
This is a follow-up to 45a7f5b62d0b1b21763c1c94255ef2309ea4280b "Keep WID ranges
sorted, and join adjacent ones".  While SfxItemSet::MergeRange relies on the
m_pWhichRanges being sorted (and, under DBG_UTIL, asserts if they are not), the
various SfxItemSet constructors curiously only check (via assert or DBG_ASSERT)
that each individual range has an upper bound not smaller than its lower bound.
Arguably, all SfxItemSet instances should fulfill the stronger guarantees
required and checked by MergeRange.

And in many cases the ranges are statically known, so that the checking can
happen at compile time.  Therefore, replace the two SfxItemSet ctors taking
explicit ranges with two other ctors that actually do proper checking.  The
(templated) overload taking an svl::Items struct should be used in all cases
where the range values are statically known at compile time, while the overload
taking a std::initializer_list<Pair> is for the remaining cases (that can only
do runtime checking via assert).  Most of those latter cases are simple cases
with a single range covering a single item, but a few are more complex.

(At least some of the uses of the existing SfxItemSet overload taking a

  const sal_uInt16* pWhichPairTable

can probably also be strengthened, but that is left for another day.)

This commit is the first in a series of two.  Apart from the manual changes to
compilerplugins/clang/store/sfxitemsetrewrite.cxx, include/svl/itemset.hxx, and
svl/source/items/itemset.cxx, it only consists of automatic rewriting of the
relevant SfxItemSet ctor calls (plus a few required manual fixes, see next).
But it does not yet check that the individual ranges are properly sorted (see
the TODO in svl::detail::validGap).  That check will be enabled, and the ensuing
manual fixes will be made in a follow-up commit, to reduce the likelyhood of
accidents.

There were three cases of necessary manual intervention:

* sw/source/core/unocore/unostyle.cxx uses eAtr of enum type RES_FRMATR in
braced-init-list syntax now, so needs explicit narrowing conversion to
sal_uInt16.

* In sw/source/uibase/uiview/formatclipboard.cxx, the trailiing comma in the
definition of macro FORMAT_PAINTBRUSH_FRAME_IDS needed to be removed manually.

* In svx/source/svdraw/svdoashp.cxx, svx/source/svdraw/svdotext.cxx,
sw/source/uibase/app/docstyle.cxx, sw/source/uibase/shells/frmsh.cxx,
sw/source/uibase/shells/grfsh.cxx, and sw/source/uibase/shells/textsh1.cxx,
some comments had to be put back (see "TODO: the replaced range can contain
relevant comments" in compilerplugins/clang/store/sfxitemsetrewrite.cxx).

A few uses of the variadic form erroneously used nullptr instead of 0 for
termination.  But this should have been harmless even if promoted std::nullptr_t
is larger than promoted sal_uInt16, assuming that the part of the nullptr value
that was interpreted as sal_uInt16/promoted int was all-zero bits.  Similarly,
some uses made the harmless error of using 0L instead of 0.

Change-Id: I2afea97282803cb311b9321a99bb627520ef5e35
Reviewed-on: https://gerrit.libreoffice.org/38861
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
2017-06-16 17:28:41 +02:00
Noel Grandin
2c83c40b43 improve unusedfields loplugin
to ignore assignments when doing writeonly analysis

Change-Id: I9eb6f2594003a610582dbc20acb7ccf14ef72c6c
2017-06-15 11:36:05 +02:00
Stephan Bergmann
423dacde87 Generalize loplugin:stringcopy to loplugin:redundantcopy
(such redundant std::unique_ptr copies could happen when changing parts of the
code base to make use of std::unique_ptr individually)

Change-Id: Ib48a45a212f9426a775c7f379bc5d3c92230218a
2017-06-13 17:00:30 +02:00
Stephan Bergmann
bd5a895c2b DbgCheckItemSet is gone
...since 87c9465262680dec09efb869800859aa65ab1d19 "Bin unused function
DbgCheckItemSet"

Change-Id: I109598dc5e087697d77b96a0ba2fb178d47b3aa6
2017-06-08 16:40:12 +02:00
Stephan Bergmann
fee8afc229 getBody() can be null for a defaulted dtor
Not sure why that started to pop up only now, maybe something changed with
recent Clang trunk.

Change-Id: Ib6587b66afbf3e43d92c78432c0bfd61c74ba6c5
2017-06-06 09:23:17 +02:00
Stephan Bergmann
690f2f5c46 Avoid loplugin:unreffun
Change-Id: I75ea46f257046bb42b2bfad3a5bd4450868e0d69
2017-06-06 08:04:06 +02:00
Stephan Bergmann
2725f88465 Improved loplugin:cstylecast to reference types
Change-Id: Ie95ab6d588cfe40cc9748ce526b80d06fe825da5
2017-06-05 21:18:14 +02:00
Stephan Bergmann
0f84a32f5b Improved loplugin:redundantcast, const/static_cast combinations
Change-Id: I3b24327835cd4e1842ee6e9b87ab06efa25a4bbf
2017-06-05 21:17:59 +02:00
Stephan Bergmann
0763d8413e Reduce loplugin:redundantcast warnings about functional casts even futher
Change-Id: I8884e17c453831e048c43012ee176093c5b2f99e
2017-06-05 21:17:55 +02:00
Andrea Gelmini
ac341548dc Fix typos
Change-Id: I9eb05432732a04e816946fbb13001df100a31f73
Reviewed-on: https://gerrit.libreoffice.org/38395
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2017-06-05 17:58:20 +02:00
Stephan Bergmann
c855400e96 Reduce loplugin:redundantcast warnings about functional casts even futher
Change-Id: Ieae9b5c9c7c6d9b8459e5d163f55d8f5024adfae
2017-06-02 14:00:08 +02:00
Stephan Bergmann
95645cbf0a Improved loplugin:redundantcast const_cast handling
Change-Id: I4c24ff5d9d5e74bef2a4040c6308c504282af55d
2017-06-02 13:31:37 +02:00
Stephan Bergmann
5872221094 Reorganize tests
Change-Id: Ic3d9e55b2730a3ea01cc6c7c9fbdd80a1e653c7e
2017-06-02 10:39:53 +02:00
Stephan Bergmann
1fce984051 Make loplugin:redundantcast functional cast warnings more verbose
(useful when types involve typedefs)

Change-Id: I93e8962fd4b9c4ef79990e057dfa07538380008c
2017-06-02 10:35:05 +02:00
Stephan Bergmann
beae2dd6c8 Improved loplugin:redundantcast static_cast handling
Change-Id: I74e4ebda40f95661c5ae344132fcabbbf08ab0a4
2017-06-02 09:38:15 +02:00
Stephan Bergmann
93aeaa75a4 Improve suppression of loplugin:redundantcast in CPPUNIT_ASSERT
Change-Id: I65f95e7245f08592ea11cc75e1cf34dcbdf16b40
2017-06-01 14:37:02 +02:00
Noel Grandin
7c9f9ab982 remove overly large loplugin result file
should not have been committed in the first place, was an accident

Change-Id: Ie38cc77624bae5b3f9cc110085d0fe19b26c75c6
2017-06-01 11:20:28 +02:00
Andrea Gelmini
5482ee62a5 Fix typos
Change-Id: Ic7fbd750321e4cfde1cfb0e04ffb545bb1f66d9c
Reviewed-on: https://gerrit.libreoffice.org/37921
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Julien Nabet <serval2412@yahoo.fr>
2017-06-01 09:42:53 +02:00
Stephan Bergmann
82dc186a2a Avoid "default initialization ... without ... default constructor" error
Change-Id: Ic336b33bd747cd55955231cbe0b5a9d474adf3ab
2017-06-01 09:23:52 +02:00
Stephan Bergmann
967e9e6bbb Add some loplugin:redundantcast tests
Change-Id: I5c39a745b70655f92953ec785d01a3a52d9ec42b
2017-05-31 18:04:22 +02:00
Stephan Bergmann
22a6911929 The updated values of t1, t2 are unused
...since f1bbda1c26dc16642038ea70288eec60b43520b6 "loplugin:cstylecast: deal
with remaining pointer casts"

Change-Id: Idecc702344c674e6f39051e4f8c2114017e317cb
2017-05-31 12:05:43 +02:00
Stephan Bergmann
bef247d137 DataRecursionQueue was only introduced in Clang 3.8
(r253948 "Use data recursion in RecursiveASTVisitor when traversing Stmt and
Expr nodes")

Change-Id: I393474048ecbe0f6b7f19f00c2f830f495b2b6f0
2017-05-31 09:18:08 +02:00
Stephan Bergmann
7d858ad057 Restrict loplugin:redundantcast to "real" casts
Change-Id: Ifc9de898e5c9a084cbfd739625c679185c3a1534
2017-05-30 15:46:55 +02:00
Stephan Bergmann
3dda91dda8 Traverse InitListExpr only once
Arbitrarily chosing to traverse the semantic instead of the syntactic form.

Change-Id: Id1b4e49421a5550bb2fa9f0d7e6f83bf7abb6ebb
2017-05-30 14:39:23 +02:00
Stephan Bergmann
f6dda4e160 Make loplugin:redundantcast accept bool(FD_ISSET(...)) again
Change-Id: I4e96c55c246cf806f17df31844a00d0e8a5e4f56
2017-05-30 13:40:53 +02:00
Noel Grandin
2ccde70d60 teach redundantcast plugin about functional casts
Change-Id: Iac8ccd17d9e46ebb2cb55db7adb06c469bbd4ea0
Reviewed-on: https://gerrit.libreoffice.org/37910
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-05-30 08:50:31 +02:00
Noel Grandin
4a340e36e8 loplugin:constantparam
add the results files so I can just see the diff in future

Change-Id: Ia20a1aa6418be95ed620719cde340c00b7b053e1
Reviewed-on: https://gerrit.libreoffice.org/37988
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-05-25 08:12:17 +02:00
Noel Grandin
0a58848fdd loplugin:unusedfields
Change-Id: Ib91c6d23a1af3735d9c030eaf9efae817f513c58
Reviewed-on: https://gerrit.libreoffice.org/37982
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-05-24 12:53:15 +02:00
Noel Grandin
d1e47b1428 enhance useuniqueptr loplugin
teach it to look for the following sequence in a destructor:
    delete m_pfoo;
    m_pfoo = nullptr;

Change-Id: Icd6271a63a024e32b53cc9e599f8f59952160380
Reviewed-on: https://gerrit.libreoffice.org/37900
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-05-23 09:31:20 +02:00
Andrea Gelmini
e1e3def8cc Fix typos
Change-Id: I438b6719817e0bbb47370ec54561eed2bc402cba
Reviewed-on: https://gerrit.libreoffice.org/37783
Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-05-21 12:59:32 +02:00
Stephan Bergmann
8b1fcedcd1 ...and re-eanble loplugin:stringcopy again
<http://reviews.llvm.org/D22128> "Make CastExpr::getSubExprAsWritten look
through implicit temporary under CK_ConstructorConversion" was biting me again.
(I had originally developed loplugin:stringcopy against a Clang build that
includes my local fix for that issue.  I really need to see to get that resolved
upstream...)

(And while 957874168491f4b030fda85c65dd969aae82a670 "loplugin:stringcopy" was
actually a false positive, it doesn't hurt either, so just keep it.)

Change-Id: I726956adfbe67681005173cfdfed2e4b4cd6253d
2017-05-19 23:57:03 +02:00
Stephan Bergmann
96e5f6670b Disable loplugin:stringcopy for now
Some versions of Clang apparently have an issue with
CastExpr::getSubExprAsWritten, causing false postivies as in
957874168491f4b030fda85c65dd969aae82a670 "loplugin:stringcopy", where
getSubExprAsWritten in

> CXXFunctionalCastExpr 0x114a333a8 'class rtl::OUString' functional cast to class rtl::OUString <ConstructorConversion>
> `-CXXBindTemporaryExpr 0x114a33388 'class rtl::OUString' (CXXTemporary 0x114a33380)
>   `-CXXConstructExpr 0x114a33348 'class rtl::OUString' 'void (class rtl::OUString &&)' elidable
>     `-MaterializeTemporaryExpr 0x114a33330 'class rtl::OUString' xvalue
>       `-CXXBindTemporaryExpr 0x114a33310 'class rtl::OUString' (CXXTemporary 0x114a33308)
>         `-ImplicitCastExpr 0x114a332f0 'class rtl::OUString' <UserDefinedConversion>
>           `-CXXMemberCallExpr 0x114a332c8 'class rtl::OUString'
>             `-MemberExpr 0x114a33290 '<bound member function type>' .operator OUString 0x1149b3b60
>               `-DeclRefExpr 0x114a324b8 'class jfw::CXmlCharPtr' lvalue Var 0x114a31ce0 'sUser' 'class jfw::CXmlCharPtr'

erroneously returns the MaterializeTemporaryExpr instead of looking through all
the way down to the DeclRefExpr.  Will need further investigation.

Change-Id: I579cd6047b8bbf8833123ce5ad47ae7e3a33eb12
2017-05-19 23:28:19 +02:00
Stephan Bergmann
b6778e921f loplugin:stringcopy
Change-Id: Ib04ef019996888166c25ad140b7c718a173a782a
2017-05-19 17:20:05 +02:00
Noel Grandin
fd00bd0f69 loplugin:unusedfields
make it a little smarter in dealing with fields that are smart pointers

Change-Id: I44072105170882dc29fb19558f1065cffc7e5f11
Reviewed-on: https://gerrit.libreoffice.org/37751
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-05-19 09:17:06 +02:00
Stephan Bergmann
9b51d16771 Remove unnecessary restrictions
Change-Id: Idc0db273f7ad2d6b11113752ca01a1f2a327e991
2017-05-18 14:26:47 +02:00
Stephan Bergmann
a7551b34ad Rewrite in macro arguments
Change-Id: I6ae619edac26fe06d1f86f139b7cf71ce31146d4
2017-05-18 14:25:38 +02:00
Stephan Bergmann
64e5915b7a Avoid nested automatic rewrites
...which would come out garbled.  One place is

>             bool bRet = SfxItemState::SET == pSet->GetItemState( i, rAttr.Which() != RES_TXTATR_AUTOFMT, &pItem );

in SwAttrHandler::PushAndChg (sw/source/core/text/atrstck.cxx)

Change-Id: I1486313b25850dc59e10edb38b8bd28a30e6aa63
2017-05-18 14:21:58 +02:00
Stephan Bergmann
8584b7f57c Refuse to rewrite in workdir
...instead of merely getting a warning from PluginHandler::HandleTranslationUnit
after the fact.  Such automatic rewriting should probably never be what one
wants.

Change-Id: I3829007224a197ebb4d55d24323b375cbbdf815c
2017-05-18 14:18:58 +02:00
Stephan Bergmann
df8d092c3a Adapt pathname checks to mixed usage of \ and / on Windows
Change-Id: I91bc89a9076c6642e06b238f65f2d31a1d20c6b5
2017-05-18 09:56:01 +02:00
Noel Grandin
4c05834a36 loplugin:unusedmethods
Change-Id: I1c50d176e793397a1f9625f797a3750cf191a61c
Reviewed-on: https://gerrit.libreoffice.org/37679
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-05-18 09:17:43 +02:00
Stephan Bergmann
6a21827e97 Remove unused var
Change-Id: I187df1a6f5bf5d870820f60c6dca1ac3beb8cf22
2017-05-17 15:01:32 +02:00
Stephan Bergmann
133d06baef Remove unused var
Change-Id: Id0266ad01eaabf2d9555e99f4a4c1c2300bb8be7
2017-05-16 19:44:25 +02:00
Stephan Bergmann
189c3a098e Extend loplugin:comparisonwithconstant beyond integral types
Change-Id: Id3a8fd5d8b9975d3ae49af0648b39454310495fa
2017-05-16 17:19:11 +02:00
Stephan Bergmann
e85fcef1af Try to fix loplugin:comparisonwithconstant's rewrite-with-macros issue
...that had plagued 2e293a731c1559c9869dfcb32491bc600fc18e4e "new
loplugin/rewriter comparisonwithconstant" (in sal/osl/unx/pipe.cxx), and
auto-rewrite the remaining occurrences in sal (that the mentioned commit had
failed to address, for whatever reason)

Change-Id: I3dc3bae8dd92ba8bf576f6e06e7c9ee21f883661
2017-05-16 16:49:03 +02:00
Noel Grandin
482ef1bfe9 loplugin:comparisonwithconstant in accessibility
Change-Id: I934c78ec8daec656ca656d5c784f80895abfd2e4
Reviewed-on: https://gerrit.libreoffice.org/37666
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-05-16 11:57:44 +02:00
Noel Grandin
d39717a6d6 tighten up the check a little more
Change-Id: Ic19364d2daa064a20da0ed9d9641f1646d8f6ce3
2017-05-16 09:39:23 +02:00
Noel Grandin
98c4cd372b loplugin:unusedfields improve write-only analysis
by whitelisting a couple of methods we know only write to their
parameters

Change-Id: Id7aef9c03c23d10c27707b21eb9a0db4a6c2757c
Reviewed-on: https://gerrit.libreoffice.org/37647
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-05-16 08:45:17 +02:00