From 2226d69ae3f416c15f3718f43a05055091ea50d2 Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Tue, 30 Oct 2018 10:41:54 +0100 Subject: Make SbiProcDef::Match more readable This reverts commit 02caaef29d60 ("loplugin:useuniqueptr in SbiProcDef") and is hopefully easier to follow. Change-Id: I46be2b3c7a933743795d89fe17a2c499c6983382 Reviewed-on: https://gerrit.libreoffice.org/62548 Tested-by: Jenkins Reviewed-by: Noel Grandin Reviewed-by: Mike Kaganski Reviewed-by: Jan-Marek Glogowski --- basic/source/comp/dim.cxx | 4 ++-- basic/source/comp/symtbl.cxx | 12 ++++++++---- basic/source/inc/symtbl.hxx | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'basic') diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx index 3a984ce8c824..dc6bf5260448 100644 --- a/basic/source/comp/dim.cxx +++ b/basic/source/comp/dim.cxx @@ -1032,7 +1032,7 @@ void SbiParser::DefDeclare( bool bPrivate ) } else { - pDef->Match( std::unique_ptr(p) ); + pDef->Match( p ); } } else @@ -1214,7 +1214,7 @@ void SbiParser::DefProc( bool bStatic, bool bPrivate ) } } - pDef->Match( std::unique_ptr(pProc) ); + pDef->Match( pProc ); } else { diff --git a/basic/source/comp/symtbl.cxx b/basic/source/comp/symtbl.cxx index 2002f3fce278..351cdaa818e5 100644 --- a/basic/source/comp/symtbl.cxx +++ b/basic/source/comp/symtbl.cxx @@ -409,7 +409,7 @@ void SbiProcDef::SetType( SbxDataType t ) // if the match is OK, pOld is replaced by this in the pool // pOld is deleted in any case! -void SbiProcDef::Match( std::unique_ptr pOld ) +void SbiProcDef::Match( SbiProcDef* pOld ) { SbiSymDef *pn=nullptr; // parameter 0 is the function name @@ -433,16 +433,20 @@ void SbiProcDef::Match( std::unique_ptr pOld ) pOld->pIn->GetParser()->SetCol1( 0 ); pOld->pIn->GetParser()->Error( ERRCODE_BASIC_BAD_DECLARATION, aName ); } + if( !pIn && pOld->pIn ) { // Replace old entry with the new one nPos = pOld->nPos; nId = pOld->nId; pIn = pOld->pIn; - std::unique_ptr tmp(this); - std::swap(pIn->m_Data[nPos], tmp); - (void)tmp.release(); + + // don't delete pOld twice, if it's stored in m_Data + if (pOld == pIn->m_Data[nPos].get()) + pOld = nullptr; + pIn->m_Data[nPos].reset(this); } + delete pOld; } void SbiProcDef::setPropertyMode( PropertyMode ePropMode ) diff --git a/basic/source/inc/symtbl.hxx b/basic/source/inc/symtbl.hxx index 3c0f9bf0128e..64a11ea814f3 100644 --- a/basic/source/inc/symtbl.hxx +++ b/basic/source/inc/symtbl.hxx @@ -194,7 +194,7 @@ public: // Match with a forward-declaration. The parameter names are // compared and the forward declaration is replaced by this - void Match( std::unique_ptr pForward ); + void Match( SbiProcDef* pForward ); private: SbiProcDef( const SbiProcDef& ) = delete; -- cgit