diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-01-12 08:22:39 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-01-15 07:28:35 +0100 |
commit | 397d5cbc3c04da7693e2e1f3e99b0d8e431bfff2 (patch) | |
tree | d064789b3a170293ff0f57b7f2b1b1b79159b18b | |
parent | a2f86708a5740ce9fd2a3a6ab69685d8fb53dd6c (diff) |
loplugin:useuniqueptr in Cursor
Change-Id: I5de300709409311b7a1d451ee1d314596cf2e879
Reviewed-on: https://gerrit.libreoffice.org/47836
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | compilerplugins/clang/test/useuniqueptr.cxx | 12 | ||||
-rw-r--r-- | compilerplugins/clang/useuniqueptr.cxx | 5 | ||||
-rw-r--r-- | include/vcl/cursor.hxx | 3 | ||||
-rw-r--r-- | vcl/source/window/cursor.cxx | 15 |
4 files changed, 24 insertions, 11 deletions
diff --git a/compilerplugins/clang/test/useuniqueptr.cxx b/compilerplugins/clang/test/useuniqueptr.cxx index 43002ec59a68..ddd30c73ae62 100644 --- a/compilerplugins/clang/test/useuniqueptr.cxx +++ b/compilerplugins/clang/test/useuniqueptr.cxx @@ -112,4 +112,16 @@ class Foo9 { delete m_pbar3; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}} } }; +// no warning expected +class Foo10 { + XXX* m_pbar1; + ~Foo10() + { + if (m_pbar1 != getOther()) + { + delete m_pbar1; + } + } + XXX* getOther() { return nullptr; } +}; /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index 99ef6928533e..c14d5fc5a57b 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -88,6 +88,8 @@ void UseUniquePtr::CheckForUnconditionalDelete(const CXXDestructorDecl* destruct { if (!isa<MemberExpr>(binaryOp->getLHS()->IgnoreImpCasts())) continue; + if (!isa<CXXNullPtrLiteralExpr>(binaryOp->getRHS()->IgnoreImpCasts())) + continue; } else continue; @@ -109,6 +111,9 @@ void UseUniquePtr::CheckForUnconditionalDelete(const CXXDestructorDecl* destruct } } +/** + * Check the delete expression in a destructor. + */ void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, const CXXDeleteExpr* deleteExpr) { const ImplicitCastExpr* pCastExpr = dyn_cast<ImplicitCastExpr>(deleteExpr->getArgument()); diff --git a/include/vcl/cursor.hxx b/include/vcl/cursor.hxx index b5c547f68463..0a0deb3e84bc 100644 --- a/include/vcl/cursor.hxx +++ b/include/vcl/cursor.hxx @@ -25,6 +25,7 @@ #include <vcl/dllapi.h> #include <vcl/vclptr.hxx> #include <rtl/ustring.hxx> +#include <memory> class Timer; struct ImplCursorData; @@ -44,7 +45,7 @@ namespace vcl class VCL_DLLPUBLIC Cursor { private: - ImplCursorData* mpData; + std::unique_ptr<ImplCursorData> mpData; VclPtr<vcl::Window> mpWindow; // only for shadow cursor long mnSlant; Size maSize; diff --git a/vcl/source/window/cursor.cxx b/vcl/source/window/cursor.cxx index 9f4d4a872d07..bfdfe67464e8 100644 --- a/vcl/source/window/cursor.cxx +++ b/vcl/source/window/cursor.cxx @@ -151,7 +151,7 @@ void vcl::Cursor::ImplDraw() mpData->maPixSize.Width() = pWindow->GetSettings().GetStyleSettings().GetCursorSize(); // calculate output area and display - ImplCursorInvert( mpData ); + ImplCursorInvert( mpData.get() ); mpData->mbCurVisible = true; } } @@ -160,7 +160,7 @@ void vcl::Cursor::ImplRestore() { assert( mpData && mpData->mbCurVisible ); - ImplCursorInvert( mpData ); + ImplCursorInvert( mpData.get() ); mpData->mbCurVisible = false; } @@ -185,7 +185,7 @@ void vcl::Cursor::ImplDoShow( bool bDrawDirect, bool bRestore ) { if ( !mpData ) { - mpData = new ImplCursorData; + mpData.reset( new ImplCursorData ); mpData->mbCurVisible = false; mpData->maTimer.SetInvokeHandler( LINK( this, Cursor, ImplTimerHdl ) ); mpData->maTimer.SetDebugName( "vcl ImplCursorData maTimer" ); @@ -333,13 +333,8 @@ vcl::Cursor::Cursor( const Cursor& rCursor ) : vcl::Cursor::~Cursor() { - if ( mpData ) - { - if ( mpData->mbCurVisible ) - ImplRestore(); - - delete mpData; - } + if (mpData && mpData->mbCurVisible) + ImplRestore(); } void vcl::Cursor::SetStyle( sal_uInt16 nStyle ) |