diff options
-rw-r--r-- | compilerplugins/clang/test/unusedfields.cxx | 44 | ||||
-rw-r--r-- | compilerplugins/clang/unusedfields.cxx | 44 | ||||
-rw-r--r-- | dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx | 1 | ||||
-rw-r--r-- | sd/source/filter/eppt/pptx-animations-nodectx.cxx | 5 | ||||
-rw-r--r-- | sd/source/filter/eppt/pptx-animations-nodectx.hxx | 1 | ||||
-rw-r--r-- | sfx2/source/control/recentdocsviewitem.cxx | 3 | ||||
-rw-r--r-- | sfx2/source/control/recentdocsviewitem.hxx | 1 | ||||
-rw-r--r-- | svx/source/dialog/framelinkarray.cxx | 5 | ||||
-rw-r--r-- | sw/source/uibase/docvw/edtwin.cxx | 3 | ||||
-rw-r--r-- | sw/source/uibase/inc/shdwcrsr.hxx | 5 |
10 files changed, 84 insertions, 28 deletions
diff --git a/compilerplugins/clang/test/unusedfields.cxx b/compilerplugins/clang/test/unusedfields.cxx index b545f4b1a89f..c936460bbea5 100644 --- a/compilerplugins/clang/test/unusedfields.cxx +++ b/compilerplugins/clang/test/unusedfields.cxx @@ -11,6 +11,7 @@ // expected-no-diagnostics #else +#include <map> #include <memory> #include <vector> #include <ostream> @@ -377,6 +378,49 @@ namespace TouchFromOutsideAnalysis1 }; }; +namespace WriteOnlyAnalysis4 +{ + struct ImplTabCtrlData + // expected-error@-1 {{read maLayoutLineToPageId [loplugin:unusedfields]}} + // expected-error@-2 {{outside maLayoutLineToPageId [loplugin:unusedfields]}} + { + std::map< int, int > maLayoutLineToPageId; + }; + class TabControl + // expected-error@-1 {{read mpTabCtrlData [loplugin:unusedfields]}} + // expected-error@-2 {{outside-constructor mpTabCtrlData [loplugin:unusedfields]}} + { + std::unique_ptr<ImplTabCtrlData> mpTabCtrlData; + + void foo(int nLine, int& rPageId) + { + rPageId = mpTabCtrlData->maLayoutLineToPageId[ nLine ]; + } + }; +} + +namespace WriteOnlyAnalysis5 +{ + struct ImplTabCtrlData + // expected-error@-1 {{read maLayoutLineToPageId [loplugin:unusedfields]}} + // expected-error@-2 {{write maLayoutLineToPageId [loplugin:unusedfields]}} + // expected-error@-3 {{outside maLayoutLineToPageId [loplugin:unusedfields]}} + { + std::map< int, int > maLayoutLineToPageId; + }; + class TabControl + // expected-error@-1 {{read mpTabCtrlData [loplugin:unusedfields]}} + // expected-error@-2 {{outside-constructor mpTabCtrlData [loplugin:unusedfields]}} + { + std::unique_ptr<ImplTabCtrlData> mpTabCtrlData; + + void foo(int nLine, int nPageId) + { + mpTabCtrlData->maLayoutLineToPageId[ nLine ] = nPageId; + } + }; +} + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx index 68588cd7c694..ca5eb3eb00b3 100644 --- a/compilerplugins/clang/unusedfields.cxx +++ b/compilerplugins/clang/unusedfields.cxx @@ -168,6 +168,7 @@ private: void checkIfWrittenTo(const FieldDecl* fieldDecl, const Expr* memberExpr); bool isSomeKindOfZero(const Expr* arg); bool checkForWriteWhenUsingCollectionType(const CXXMethodDecl * calleeMethodDecl); + bool checkForUsingMap(const CXXMethodDecl * calleeMethodDecl); bool IsPassedByNonConst(const FieldDecl* fieldDecl, const Stmt * child, CallerWrapper callExpr, CalleeWrapper calleeFunctionDecl); compat::optional<CalleeWrapper> getCallee(CallExpr const *); @@ -831,6 +832,7 @@ void UnusedFields::checkIfWrittenTo(const FieldDecl* fieldDecl, const Expr* memb } else if (auto operatorCallExpr = dyn_cast<CXXOperatorCallExpr>(parent)) { + bool walk = false; auto callee = getCallee(operatorCallExpr); if (callee) { @@ -839,16 +841,24 @@ void UnusedFields::checkIfWrittenTo(const FieldDecl* fieldDecl, const Expr* memb if (calleeMethodDecl && operatorCallExpr->getArg(0) == child) { if (!calleeMethodDecl->isConst()) - bPotentiallyWrittenTo = checkForWriteWhenUsingCollectionType(calleeMethodDecl); + { + // If we are accessing a map entry, we want to keep walking up to determine + // if it is written to. + if (checkForUsingMap(calleeMethodDecl)) + walk = true; + else + bPotentiallyWrittenTo = checkForWriteWhenUsingCollectionType(calleeMethodDecl); + } } else if (IsPassedByNonConst(fieldDecl, child, operatorCallExpr, *callee)) - { bPotentiallyWrittenTo = true; - } } else bPotentiallyWrittenTo = true; // conservative, could improve - break; + if (walk) + walkUp(); + else + break; } else if (auto cxxMemberCallExpr = dyn_cast<CXXMemberCallExpr>(parent)) { @@ -980,20 +990,20 @@ bool UnusedFields::checkForWriteWhenUsingCollectionType(const CXXMethodDecl * ca { auto const tc = loplugin::TypeCheck(calleeMethodDecl->getParent()); bool listLike = false, setLike = false, mapLike = false, cssSequence = false; - if (tc.Class("deque").StdNamespace() - || tc.Class("list").StdNamespace() - || tc.Class("queue").StdNamespace() - || tc.Class("vector").StdNamespace()) + // Noting that I am deliberately not calling StdNamespace() on these checks, the loplugin::TypeCheck + // code seems to be unreliable when dealing with ClassTemplateSpecializationDecl. + if (tc.Class("deque") + || tc.Class("list") + || tc.Class("queue") + || tc.Class("vector")) { listLike = true; } - else if (tc.Class("set").StdNamespace() - || tc.Class("unordered_set").StdNamespace()) + else if (tc.Class("set") || tc.Class("unordered_set")) { setLike = true; } - else if (tc.Class("map").StdNamespace() - || tc.Class("unordered_map").StdNamespace()) + else if (tc.Class("map") || tc.Class("unordered_map")) { mapLike = true; } @@ -1040,6 +1050,16 @@ bool UnusedFields::checkForWriteWhenUsingCollectionType(const CXXMethodDecl * ca return true; } +bool UnusedFields::checkForUsingMap(const CXXMethodDecl * calleeMethodDecl) +{ + auto const tc = loplugin::TypeCheck(calleeMethodDecl->getParent()); + if (!(tc.Class("map") || tc.Class("unordered_map"))) + return false; + if (!calleeMethodDecl->isOverloadedOperator()) + return false; + return calleeMethodDecl->getOverloadedOperator() == OO_Subscript; +} + bool UnusedFields::IsPassedByNonConst(const FieldDecl* fieldDecl, const Stmt * child, CallerWrapper callExpr, CalleeWrapper calleeFunctionDecl) { diff --git a/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx b/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx index 543bd3e80d09..776337ebacb1 100644 --- a/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx +++ b/dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx @@ -236,7 +236,6 @@ namespace dbaui TypedWhichId<SfxInt32Item> m_nPortId; - std::unique_ptr<weld::Label> m_xHeaderText; std::unique_ptr<weld::Entry> m_xETDatabasename; std::unique_ptr<weld::Entry> m_xETHostname; std::unique_ptr<weld::SpinButton> m_xNFPortNumber; diff --git a/sd/source/filter/eppt/pptx-animations-nodectx.cxx b/sd/source/filter/eppt/pptx-animations-nodectx.cxx index 585917b4f864..9efd07d6a665 100644 --- a/sd/source/filter/eppt/pptx-animations-nodectx.cxx +++ b/sd/source/filter/eppt/pptx-animations-nodectx.cxx @@ -97,7 +97,6 @@ bool initCondList(const Any& rAny, std::vector<Cond>& rList, bool bIsMainSeqChil NodeContext::NodeContext(const Reference<XAnimationNode>& xNode, bool bMainSeqChild, bool bIsIterateChild) : mxNode(xNode) - , mbMainSeqChild(bMainSeqChild) , mbValid(true) , mbOnSubTnLst(false) , mnEffectNodeType(-1) @@ -111,10 +110,10 @@ NodeContext::NodeContext(const Reference<XAnimationNode>& xNode, bool bMainSeqCh // Put event triggered Audio time nodes to SubTnLst. // Add other types of nodes once we find more test cases. - mbOnSubTnLst = initCondList(getNodeForCondition()->getBegin(), maBeginCondList, mbMainSeqChild) + mbOnSubTnLst = initCondList(getNodeForCondition()->getBegin(), maBeginCondList, bMainSeqChild) && mxNode->getType() == AnimationNodeType::AUDIO; - initCondList(getNodeForCondition()->getEnd(), maEndCondList, mbMainSeqChild); + initCondList(getNodeForCondition()->getEnd(), maEndCondList, bMainSeqChild); } void NodeContext::initUserData() diff --git a/sd/source/filter/eppt/pptx-animations-nodectx.hxx b/sd/source/filter/eppt/pptx-animations-nodectx.hxx index 14aeacd45c99..c25991a85a23 100644 --- a/sd/source/filter/eppt/pptx-animations-nodectx.hxx +++ b/sd/source/filter/eppt/pptx-animations-nodectx.hxx @@ -22,7 +22,6 @@ typedef std::unique_ptr<NodeContext> NodeContextPtr; class NodeContext { const css::uno::Reference<css::animations::XAnimationNode> mxNode; - const bool mbMainSeqChild; std::vector<NodeContextPtr> maChildNodes; std::vector<Cond> maBeginCondList; diff --git a/sfx2/source/control/recentdocsviewitem.cxx b/sfx2/source/control/recentdocsviewitem.cxx index 57a670b37c53..240ef0c32d9d 100644 --- a/sfx2/source/control/recentdocsviewitem.cxx +++ b/sfx2/source/control/recentdocsviewitem.cxx @@ -128,7 +128,6 @@ RecentDocsViewItem::RecentDocsViewItem(sfx2::RecentDocsView &rView, const OUStri mrParentView(rView), maURL(rURL), m_isReadOnly(isReadOnly), - m_isPinned(isPinned), m_bRemoveIconHighlighted(false), m_aRemoveRecentBitmap(BMP_RECENTDOC_REMOVE), m_aRemoveRecentBitmapHighlighted(BMP_RECENTDOC_REMOVE_HIGHLIGHTED) @@ -231,7 +230,7 @@ RecentDocsViewItem::RecentDocsViewItem(sfx2::RecentDocsView &rView, const OUStri maTitle = aTitle; maPreview1 = aThumbnail; - mbPinned = m_isPinned; + mbPinned = isPinned; } ::tools::Rectangle RecentDocsViewItem::updateHighlight(bool bVisible, const Point& rPoint) diff --git a/sfx2/source/control/recentdocsviewitem.hxx b/sfx2/source/control/recentdocsviewitem.hxx index 0fe399a1fe3b..792e78ab9e05 100644 --- a/sfx2/source/control/recentdocsviewitem.hxx +++ b/sfx2/source/control/recentdocsviewitem.hxx @@ -52,7 +52,6 @@ private: OUString maURL; bool m_isReadOnly = false; - bool m_isPinned = false; OUString m_sHelpText; diff --git a/svx/source/dialog/framelinkarray.cxx b/svx/source/dialog/framelinkarray.cxx index 5ad6c03c770d..80a245a0f27c 100644 --- a/svx/source/dialog/framelinkarray.cxx +++ b/svx/source/dialog/framelinkarray.cxx @@ -289,7 +289,6 @@ struct ArrayImpl { // used to reduce the memory consumption of cells rtl::Reference<SfxItemPool> mxPool; - const Cell* mpDefaultCell; CellVec maCells; std::vector<sal_Int32> maWidths; std::vector<sal_Int32> maHeights; @@ -357,9 +356,9 @@ ArrayImpl::ArrayImpl( sal_Int32 nWidth, sal_Int32 nHeight ) : mbYCoordsDirty( false ), mbMayHaveCellRotation( false ) { - mpDefaultCell = &mxPool->Put(Cell()); + const Cell* pDefaultCell = &mxPool->Put(Cell()); // default-construct all vectors - maCells.resize( mnWidth * mnHeight, mpDefaultCell ); + maCells.resize( mnWidth * mnHeight, pDefaultCell ); maWidths.resize( mnWidth, 0 ); maHeights.resize( mnHeight, 0 ); maXCoords.resize( mnWidth + 1, 0 ); diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index 65ec052affff..4f83a8f52ba8 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -4550,8 +4550,7 @@ void SwEditWin::MouseMove(const MouseEvent& _rMEvt) if( rSh.GetShadowCursorPos( aDocPt, eMode, aRect, m_eOrient )) { if( !m_pShadCursor ) - m_pShadCursor.reset( new SwShadowCursor( *this, - rSh.GetViewOptions()->GetDirectCursorColor() ) ); + m_pShadCursor.reset( new SwShadowCursor( *this ) ); if( text::HoriOrientation::RIGHT != m_eOrient && text::HoriOrientation::CENTER != m_eOrient ) m_eOrient = text::HoriOrientation::LEFT; m_pShadCursor->SetPos( aRect.Pos(), aRect.Height(), static_cast< sal_uInt16 >(m_eOrient) ); diff --git a/sw/source/uibase/inc/shdwcrsr.hxx b/sw/source/uibase/inc/shdwcrsr.hxx index ec8a5f55f89b..4118b3965a99 100644 --- a/sw/source/uibase/inc/shdwcrsr.hxx +++ b/sw/source/uibase/inc/shdwcrsr.hxx @@ -28,7 +28,6 @@ class SwShadowCursor { VclPtr<vcl::Window> m_pWin; - Color m_aCol; Point m_aOldPt; tools::Long m_nOldHeight; sal_uInt16 m_nOldMode; @@ -36,8 +35,8 @@ class SwShadowCursor void DrawCursor( sal_uInt16 nMode ); public: - SwShadowCursor( vcl::Window& rWin, const Color& rCol ) - : m_pWin( &rWin ), m_aCol( rCol ), m_nOldHeight(0), m_nOldMode( USHRT_MAX ) {} + SwShadowCursor( vcl::Window& rWin ) + : m_pWin( &rWin ), m_nOldHeight(0), m_nOldMode( USHRT_MAX ) {} ~SwShadowCursor(); void SetPos( const Point& rPt, tools::Long nHeight, sal_uInt16 nMode ); |