compilerplugins/clang/test/useuniqueptr.cxx | 12 ++++++++++++ compilerplugins/clang/useuniqueptr.cxx | 5 +++++ include/vcl/cursor.hxx | 3 ++- vcl/source/window/cursor.cxx | 15 +++++---------- 4 files changed, 24 insertions(+), 11 deletions(-)
New commits: commit 397d5cbc3c04da7693e2e1f3e99b0d8e431bfff2 Author: Noel Grandin <[email protected]> Date: Fri Jan 12 08:22:39 2018 +0200 loplugin:useuniqueptr in Cursor Change-Id: I5de300709409311b7a1d451ee1d314596cf2e879 Reviewed-on: https://gerrit.libreoffice.org/47836 Tested-by: Jenkins <[email protected]> Reviewed-by: Noel Grandin <[email protected]> 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 ) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
