Kaydet (Commit) 61dfcdda authored tarafından Noel Grandin's avatar Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst b1d66892
......@@ -114,14 +114,13 @@ struct ReadOnly1 { ReadOnly1(int&); };
struct ReadOnlyAnalysis
// expected-error@-1 {{read m_f2 [loplugin:unusedfields]}}
// expected-error@-2 {{read m_f3 [loplugin:unusedfields]}}
// expected-error@-3 {{read m_f4 [loplugin:unusedfields]}}
// expected-error@-4 {{read m_f5 [loplugin:unusedfields]}}
// expected-error@-5 {{read m_f6 [loplugin:unusedfields]}}
// expected-error@-6 {{write m_f2 [loplugin:unusedfields]}}
// expected-error@-7 {{write m_f3 [loplugin:unusedfields]}}
// expected-error@-8 {{write m_f4 [loplugin:unusedfields]}}
// expected-error@-9 {{write m_f5 [loplugin:unusedfields]}}
// expected-error@-10 {{write m_f6 [loplugin:unusedfields]}}
// expected-error@-3 {{read m_f5 [loplugin:unusedfields]}}
// expected-error@-4 {{read m_f6 [loplugin:unusedfields]}}
// expected-error@-5 {{write m_f2 [loplugin:unusedfields]}}
// expected-error@-6 {{write m_f3 [loplugin:unusedfields]}}
// expected-error@-7 {{write m_f4 [loplugin:unusedfields]}}
// expected-error@-8 {{write m_f5 [loplugin:unusedfields]}}
// expected-error@-9 {{write m_f6 [loplugin:unusedfields]}}
{
int m_f1;
int m_f2;
......@@ -177,9 +176,8 @@ struct ReadOnlyAnalysis3
// add elements.
struct ReadOnlyAnalysis4
// expected-error@-1 {{read m_readonly [loplugin:unusedfields]}}
// expected-error@-2 {{read m_readwrite [loplugin:unusedfields]}}
// expected-error@-3 {{write m_readwrite [loplugin:unusedfields]}}
// expected-error@-4 {{read m_readonlyCss [loplugin:unusedfields]}}
// expected-error@-2 {{write m_readwrite [loplugin:unusedfields]}}
// expected-error@-3 {{read m_readonlyCss [loplugin:unusedfields]}}
{
std::vector<int> m_readonly;
std::vector<int> m_readwrite;
......
......@@ -586,10 +586,18 @@ void UnusedFields::checkIfReadFrom(const FieldDecl* fieldDecl, const Expr* membe
if (startswith(name, "read"))
// this is a write-only call
;
else if (startswith(name, "emplace") || name == "insert"
|| name == "erase" || name == "remove" || name == "remove_if" || name == "sort"
|| name == "push_back" || name == "pop_back"
|| name == "push_front" || name == "pop_front"
|| name == "reserve" || name == "resize"
|| name == "clear" || name == "fill")
// write-only modifications to collections
;
else if (name.find(">>=") != std::string::npos && callExpr->getArg(1) == child)
// this is a write-only call
;
else if (name == "clear" || name == "dispose" || name == "disposeAndClear" || name == "swap")
else if (name == "dispose" || name == "disposeAndClear" || name == "swap")
// we're abusing the write-only analysis here to look for fields which don't have anything useful
// being done to them, so we're ignoring things like std::vector::clear, std::vector::swap,
// and VclPtr::disposeAndClear
......
......@@ -9,9 +9,9 @@ avmedia/source/vlc/wrapper/Types.hxx:44
avmedia/source/vlc/wrapper/Types.hxx:45
libvlc_event_t::(anonymous union)::(anonymous) dummy2 const char *
avmedia/source/vlc/wrapper/Types.hxx:46
libvlc_event_t::(anonymous) padding struct (anonymous struct at /media/noel/disk2/libo4/avmedia/source/vlc/wrapper/Types.hxx:43:7)
libvlc_event_t::(anonymous) padding struct (anonymous struct at /home/noel/libo/avmedia/source/vlc/wrapper/Types.hxx:43:7)
avmedia/source/vlc/wrapper/Types.hxx:47
libvlc_event_t u union (anonymous union at /media/noel/disk2/libo4/avmedia/source/vlc/wrapper/Types.hxx:41:5)
libvlc_event_t u union (anonymous union at /home/noel/libo/avmedia/source/vlc/wrapper/Types.hxx:41:5)
avmedia/source/vlc/wrapper/Types.hxx:53
libvlc_track_description_t psz_name char *
basegfx/source/polygon/b2dtrapezoid.cxx:202
......@@ -488,11 +488,11 @@ sal/textenc/textenc.cxx:406
(anonymous namespace)::FullTextEncodingData module_ osl::Module
sc/inc/column.hxx:125
ScColumn maCellsEvent const sc::CellStoreEvent
sc/inc/compiler.hxx:256
sc/inc/compiler.hxx:255
ScCompiler::AddInMap pODFF const char *
sc/inc/compiler.hxx:257
sc/inc/compiler.hxx:256
ScCompiler::AddInMap pEnglish const char *
sc/inc/compiler.hxx:259
sc/inc/compiler.hxx:258
ScCompiler::AddInMap pUpper const char *
sc/inc/token.hxx:400
SingleDoubleRefModifier aDub struct ScComplexRefData
......@@ -586,14 +586,14 @@ sd/source/ui/view/viewshel.cxx:1211
sd::KeepSlideSorterInSyncWithPageChanges m_aContext const sd::slidesorter::controller::class SelectionObserver::Context
sdext/source/pdfimport/pdfparse/pdfparse.cxx:263
PDFGrammar::definition stream rule<ScannerT>
sdext/source/pdfimport/pdfparse/pdfparse.cxx:263
PDFGrammar::definition boolean rule<ScannerT>
sdext/source/pdfimport/pdfparse/pdfparse.cxx:263
PDFGrammar::definition name rule<ScannerT>
sdext/source/pdfimport/pdfparse/pdfparse.cxx:263
PDFGrammar::definition null_object rule<ScannerT>
sdext/source/pdfimport/pdfparse/pdfparse.cxx:263
PDFGrammar::definition stringtype rule<ScannerT>
sdext/source/pdfimport/pdfparse/pdfparse.cxx:263
PDFGrammar::definition boolean rule<ScannerT>
sdext/source/pdfimport/pdfparse/pdfparse.cxx:263
PDFGrammar::definition comment rule<ScannerT>
sdext/source/pdfimport/pdfparse/pdfparse.cxx:263
......@@ -706,11 +706,11 @@ svx/source/svdraw/svdcrtv.cxx:49
ImplConnectMarkerOverlay maObjects sdr::overlay::OverlayObjectList
svx/source/xml/xmleohlp.cxx:72
OutputStorageWrapper_Impl aTempFile class utl::TempFile
sw/inc/unosett.hxx:144
sw/inc/unosett.hxx:145
SwXNumberingRules m_pImpl ::sw::UnoImplPtr<Impl>
sw/qa/core/test_ToxTextGenerator.cxx:134
ToxTextGeneratorWithMockedChapterField mChapterFieldType class SwChapterFieldType
sw/qa/extras/uiwriter/uiwriter.cxx:4015
sw/qa/extras/uiwriter/uiwriter.cxx:4016
IdleTask maIdle class Idle
sw/source/core/crsr/crbm.cxx:64
(anonymous namespace)::CursorStateHelper m_aSaveState const class SwCursorSaveState
......@@ -758,7 +758,7 @@ ucb/source/ucp/gio/gio_mount.hxx:52
OOoMountOperationClass _gtk_reserved4 void (*)(void)
unotools/source/config/defaultoptions.cxx:94
SvtDefaultOptions_Impl m_aUserDictionaryPath class rtl::OUString
vcl/headless/svpgdi.cxx:313
vcl/headless/svpgdi.cxx:314
(anonymous namespace)::SourceHelper aTmpBmp class SvpSalBitmap
vcl/inc/canvasbitmap.hxx:44
vcl::unotools::VclCanvasBitmap m_aAlpha ::Bitmap
......@@ -800,13 +800,13 @@ vcl/inc/WidgetThemeLibrary.hxx:90
vcl::ControlDrawParameters eState enum ControlState
vcl/inc/WidgetThemeLibrary.hxx:106
vcl::WidgetThemeLibrary_t nSize uint32_t
vcl/source/app/salvtables.cxx:1659
vcl/source/app/salvtables.cxx:1660
SalInstanceEntry m_aTextFilter class SalInstanceEntry::WeldTextFilter
vcl/source/gdi/jobset.cxx:35
ImplOldJobSetupData cDeviceName char [32]
vcl/source/gdi/jobset.cxx:36
ImplOldJobSetupData cPortName char [32]
vcl/unx/gtk3/gtk3gtkinst.cxx:2712
vcl/unx/gtk3/gtk3gtkinst.cxx:2713
CrippledViewport viewport GtkViewport
vcl/unx/gtk/a11y/atkhypertext.cxx:29
(anonymous) atk_hyper_link const AtkHyperlink
......
......@@ -246,7 +246,7 @@ extensions/source/propctrlr/eformshelper.hxx:63
pcr::EFormsHelper m_aBindingUINames pcr::MapStringToPropertySet
extensions/source/update/check/updatehdl.hxx:85
UpdateHandler mbStringsLoaded _Bool
filter/source/graphicfilter/eps/eps.cxx:115
filter/source/graphicfilter/eps/eps.cxx:116
PSWriter pVDev ScopedVclPtrInstance<class VirtualDevice>
filter/source/graphicfilter/icgm/cgm.hxx:60
CGM mbPicture _Bool
......@@ -377,7 +377,7 @@ include/test/sheet/xnamedranges.hxx:38
include/test/sheet/xspreadsheets2.hxx:46
apitest::XSpreadsheets2 xDocument css::uno::Reference<css::sheet::XSpreadsheetDocument>
include/unoidl/unoidl.hxx:443
unoidl::ConstantValue union unoidl::ConstantValue::(anonymous at /media/noel/disk2/libo4/include/unoidl/unoidl.hxx:443:5)
unoidl::ConstantValue union unoidl::ConstantValue::(anonymous at /home/noel/libo/include/unoidl/unoidl.hxx:443:5)
include/unoidl/unoidl.hxx:444
unoidl::ConstantValue::(anonymous) booleanValue _Bool
include/unoidl/unoidl.hxx:445
......@@ -460,11 +460,11 @@ sal/rtl/uuid.cxx:64
UUID clock_seq_low sal_uInt8
sal/rtl/uuid.cxx:65
UUID node sal_uInt8 [6]
sc/inc/compiler.hxx:127
sc/inc/compiler.hxx:126
ScRawToken::(anonymous union)::(anonymous) eItem const class ScTableRefToken::Item
sc/inc/compiler.hxx:128
ScRawToken::(anonymous) table const struct (anonymous struct at /media/noel/disk2/libo4/sc/inc/compiler.hxx:125:9)
sc/inc/compiler.hxx:133
sc/inc/compiler.hxx:127
ScRawToken::(anonymous) table const struct (anonymous struct at /home/noel/libo/sc/inc/compiler.hxx:124:9)
sc/inc/compiler.hxx:132
ScRawToken::(anonymous) pMat class ScMatrix *const
sc/inc/formulagroup.hxx:39
sc::FormulaGroupEntry::(anonymous) mpCells class ScFormulaCell **const
......@@ -572,7 +572,7 @@ svl/source/misc/strmadpt.cxx:55
SvDataPipe_Impl::Page m_aBuffer sal_Int8 [1]
svl/source/uno/pathservice.cxx:36
PathService m_aOptions const class SvtPathOptions
svtools/source/control/tabbar.cxx:209
svtools/source/control/tabbar.cxx:210
ImplTabBarItem maHelpId const class rtl::OString
svtools/source/dialogs/insdlg.cxx:46
OleObjectDescriptor cbSize const sal_uInt32
......@@ -640,12 +640,6 @@ sw/source/core/doc/tblrwcl.cxx:83
CpyTabFrame::(anonymous) nSize SwTwips
sw/source/core/inc/swblocks.hxx:68
SwImpBlocks m_bInPutMuchBlocks _Bool
sw/source/core/inc/UndoTable.hxx:181
SwUndoTableNdsChg m_nCurrBox sal_uLong
sw/source/core/inc/UndoTable.hxx:182
SwUndoTableNdsChg m_nRelDiff sal_uInt16
sw/source/core/inc/UndoTable.hxx:182
SwUndoTableNdsChg m_nAbsDiff sal_uInt16
sw/source/core/text/atrhndl.hxx:48
SwAttrHandler::SwAttrStack m_pInitialArray class SwTextAttr *[3]
sw/source/filter/inc/rtf.hxx:32
......@@ -720,17 +714,17 @@ vcl/inc/salwtype.hxx:202
SalSurroundingTextSelectionChangeEvent mnEnd const sal_uLong
vcl/inc/salwtype.hxx:208
SalQueryCharPositionEvent mnCharPos sal_uLong
vcl/inc/svdata.hxx:274
vcl/inc/svdata.hxx:275
ImplSVNWFData mnStatusBarLowerRightOffset int
vcl/inc/svdata.hxx:280
vcl/inc/svdata.hxx:281
ImplSVNWFData mbMenuBarDockingAreaCommonBG _Bool
vcl/inc/svdata.hxx:290
ImplSVNWFData mbCenteredTabs _Bool
vcl/inc/svdata.hxx:291
ImplSVNWFData mbCenteredTabs _Bool
vcl/inc/svdata.hxx:292
ImplSVNWFData mbNoActiveTabTextRaise _Bool
vcl/inc/svdata.hxx:293
vcl/inc/svdata.hxx:294
ImplSVNWFData mbProgressNeedsErase _Bool
vcl/inc/svdata.hxx:302
vcl/inc/svdata.hxx:303
ImplSVNWFData mbRolloverMenubar _Bool
vcl/inc/toolbox.h:108
vcl::ToolBoxLayoutData m_aLineItemIds std::vector<sal_uInt16>
......@@ -908,39 +902,39 @@ vcl/source/fontsubset/sft.cxx:1049
vcl::_subHeader2 entryCount const sal_uInt16
vcl/source/fontsubset/sft.cxx:1050
vcl::_subHeader2 idDelta const sal_uInt16
vcl/source/gdi/dibtools.cxx:51
(anonymous namespace)::CIEXYZ aXyzX FXPT2DOT30
vcl/source/gdi/dibtools.cxx:52
(anonymous namespace)::CIEXYZ aXyzY FXPT2DOT30
(anonymous namespace)::CIEXYZ aXyzX FXPT2DOT30
vcl/source/gdi/dibtools.cxx:53
(anonymous namespace)::CIEXYZ aXyzY FXPT2DOT30
vcl/source/gdi/dibtools.cxx:54
(anonymous namespace)::CIEXYZ aXyzZ FXPT2DOT30
vcl/source/gdi/dibtools.cxx:64
(anonymous namespace)::CIEXYZTriple aXyzRed struct (anonymous namespace)::CIEXYZ
vcl/source/gdi/dibtools.cxx:65
(anonymous namespace)::CIEXYZTriple aXyzGreen struct (anonymous namespace)::CIEXYZ
(anonymous namespace)::CIEXYZTriple aXyzRed struct (anonymous namespace)::CIEXYZ
vcl/source/gdi/dibtools.cxx:66
(anonymous namespace)::CIEXYZTriple aXyzGreen struct (anonymous namespace)::CIEXYZ
vcl/source/gdi/dibtools.cxx:67
(anonymous namespace)::CIEXYZTriple aXyzBlue struct (anonymous namespace)::CIEXYZ
vcl/source/gdi/dibtools.cxx:106
(anonymous namespace)::DIBV5Header nV5RedMask sal_uInt32
vcl/source/gdi/dibtools.cxx:107
(anonymous namespace)::DIBV5Header nV5GreenMask sal_uInt32
(anonymous namespace)::DIBV5Header nV5RedMask sal_uInt32
vcl/source/gdi/dibtools.cxx:108
(anonymous namespace)::DIBV5Header nV5BlueMask sal_uInt32
(anonymous namespace)::DIBV5Header nV5GreenMask sal_uInt32
vcl/source/gdi/dibtools.cxx:109
(anonymous namespace)::DIBV5Header nV5BlueMask sal_uInt32
vcl/source/gdi/dibtools.cxx:110
(anonymous namespace)::DIBV5Header nV5AlphaMask sal_uInt32
vcl/source/gdi/dibtools.cxx:111
(anonymous namespace)::DIBV5Header aV5Endpoints struct (anonymous namespace)::CIEXYZTriple
vcl/source/gdi/dibtools.cxx:112
(anonymous namespace)::DIBV5Header nV5GammaRed sal_uInt32
(anonymous namespace)::DIBV5Header aV5Endpoints struct (anonymous namespace)::CIEXYZTriple
vcl/source/gdi/dibtools.cxx:113
(anonymous namespace)::DIBV5Header nV5GammaGreen sal_uInt32
(anonymous namespace)::DIBV5Header nV5GammaRed sal_uInt32
vcl/source/gdi/dibtools.cxx:114
(anonymous namespace)::DIBV5Header nV5GammaGreen sal_uInt32
vcl/source/gdi/dibtools.cxx:115
(anonymous namespace)::DIBV5Header nV5GammaBlue sal_uInt32
vcl/source/gdi/dibtools.cxx:116
(anonymous namespace)::DIBV5Header nV5ProfileData sal_uInt32
vcl/source/gdi/dibtools.cxx:117
(anonymous namespace)::DIBV5Header nV5ProfileSize sal_uInt32
(anonymous namespace)::DIBV5Header nV5ProfileData sal_uInt32
vcl/source/gdi/dibtools.cxx:118
(anonymous namespace)::DIBV5Header nV5ProfileSize sal_uInt32
vcl/source/gdi/dibtools.cxx:119
(anonymous namespace)::DIBV5Header nV5Reserved sal_uInt32
vcl/source/gdi/pdfwriter_impl.hxx:280
vcl::PDFWriterImpl::TransparencyEmit m_pSoftMaskStream std::unique_ptr<SvMemoryStream>
......@@ -952,7 +946,7 @@ vcl/source/window/menuitemlist.hxx:58
MenuItemData aAccessibleName const class rtl::OUString
vcl/unx/generic/print/bitmap_gfx.cxx:67
psp::HexEncoder mpFileBuffer sal_Char [16400]
vcl/unx/gtk3/gtk3gtkinst.cxx:1156
vcl/unx/gtk3/gtk3gtkinst.cxx:1157
out gpointer *
vcl/unx/gtk/a11y/atkwrapper.hxx:49
AtkObjectWrapper aParent const AtkObject
......
......@@ -5,9 +5,9 @@ avmedia/source/vlc/wrapper/Types.hxx:44
avmedia/source/vlc/wrapper/Types.hxx:45
libvlc_event_t::(anonymous union)::(anonymous) dummy2 const char *
avmedia/source/vlc/wrapper/Types.hxx:46
libvlc_event_t::(anonymous) padding struct (anonymous struct at /media/noel/disk2/libo4/avmedia/source/vlc/wrapper/Types.hxx:43:7)
libvlc_event_t::(anonymous) padding struct (anonymous struct at /home/noel/libo/avmedia/source/vlc/wrapper/Types.hxx:43:7)
avmedia/source/vlc/wrapper/Types.hxx:47
libvlc_event_t u union (anonymous union at /media/noel/disk2/libo4/avmedia/source/vlc/wrapper/Types.hxx:41:5)
libvlc_event_t u union (anonymous union at /home/noel/libo/avmedia/source/vlc/wrapper/Types.hxx:41:5)
avmedia/source/vlc/wrapper/Types.hxx:53
libvlc_track_description_t psz_name char *
basctl/source/inc/dlged.hxx:122
......@@ -148,10 +148,10 @@ include/sfx2/msg.hxx:119
SfxType0 nAttribs const sal_uInt16
include/sfx2/msg.hxx:132
SfxType1 pType const std::type_info *
include/sfx2/msg.hxx:132
SfxType1 createSfxPoolItemFunc std::function<SfxPoolItem *(void)>
include/sfx2/msg.hxx:132
SfxType1 nAttribs sal_uInt16
include/sfx2/msg.hxx:132
SfxType1 createSfxPoolItemFunc std::function<SfxPoolItem *(void)>
include/sfx2/msg.hxx:132
SfxType1 aAttrib struct SfxTypeAttrib [1]
include/sfx2/msg.hxx:133
......@@ -596,7 +596,7 @@ vcl/inc/WidgetThemeLibrary.hxx:90
vcl::ControlDrawParameters eState enum ControlState
vcl/inc/WidgetThemeLibrary.hxx:106
vcl::WidgetThemeLibrary_t nSize uint32_t
vcl/source/app/salvtables.cxx:667
vcl/source/app/salvtables.cxx:668
SalInstanceContainer m_xContainer VclPtr<vcl::Window>
vcl/source/gdi/jobset.cxx:35
ImplOldJobSetupData cDeviceName char [32]
......@@ -608,7 +608,7 @@ vcl/unx/generic/print/prtsetup.hxx:73
RTSPaperPage m_xContainer std::unique_ptr<weld::Widget>
vcl/unx/generic/print/prtsetup.hxx:108
RTSDevicePage m_xContainer std::unique_ptr<weld::Widget>
vcl/unx/gtk3/gtk3gtkinst.cxx:2712
vcl/unx/gtk3/gtk3gtkinst.cxx:2713
CrippledViewport viewport GtkViewport
vcl/unx/gtk/a11y/atkhypertext.cxx:29
(anonymous) atk_hyper_link const AtkHyperlink
......
......@@ -67,16 +67,13 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/unreffun \
compilerplugins/clang/test/unusedindex \
compilerplugins/clang/test/unusedenumconstants \
compilerplugins/clang/test/unusedfields \
compilerplugins/clang/test/unusedvariablecheck \
compilerplugins/clang/test/unusedvariablemore \
compilerplugins/clang/test/useuniqueptr \
compilerplugins/clang/test/vclwidgets \
))
# clang-3.8 and clang trunk differ in how they represent ranged-for
# which leads to a test failure
# compilerplugins/clang/test/unusedfields \
$(eval $(call gb_CompilerTest_use_externals,compilerplugins_clang, \
boost_headers \
cppunit \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment