summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-05-22 13:25:58 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-05-23 09:31:20 +0200
commitd1e47b1428abf1732ab4d5e219b210760d4152e0 (patch)
tree8eac1def834ba548c45a8a1a18e8e39d45eedc1d
parent919a4ef592b6026a7533a93682f39118fef29ce8 (diff)
enhance useuniqueptr loplugin
teach it to look for the following sequence in a destructor: delete m_pfoo; m_pfoo = nullptr; Change-Id: Icd6271a63a024e32b53cc9e599f8f59952160380 Reviewed-on: https://gerrit.libreoffice.org/37900 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--chart2/source/view/axes/VPolarAngleAxis.cxx6
-rw-r--r--chart2/source/view/axes/VPolarAxis.cxx4
-rw-r--r--chart2/source/view/axes/VPolarAxis.hxx3
-rw-r--r--chart2/source/view/axes/VPolarGrid.cxx6
-rw-r--r--chart2/source/view/axes/VPolarGrid.hxx3
-rw-r--r--chart2/source/view/axes/VPolarRadiusAxis.cxx2
-rw-r--r--compilerplugins/clang/test/useuniqueptr.cxx20
-rw-r--r--compilerplugins/clang/useuniqueptr.cxx26
-rw-r--r--forms/source/component/propertybaghelper.cxx11
-rw-r--r--forms/source/inc/propertybaghelper.hxx4
-rw-r--r--hwpfilter/source/hinfo.cxx6
-rw-r--r--hwpfilter/source/hinfo.h3
-rw-r--r--include/sfx2/sfxbasemodel.hxx4
-rw-r--r--include/svl/poolitem.hxx3
-rw-r--r--include/unotools/options.hxx1
-rw-r--r--include/vcl/field.hxx2
-rw-r--r--sc/inc/compiler.hxx3
-rw-r--r--sc/source/core/tool/compiler.cxx4
-rw-r--r--sd/source/ui/app/optsitem.cxx19
-rw-r--r--sd/source/ui/inc/optsitem.hxx7
-rw-r--r--sfx2/source/doc/sfxbasemodel.cxx20
-rw-r--r--solenv/CompilerTest_compilerplugins_clang.mk1
-rw-r--r--svl/source/items/sitem.cxx1
-rw-r--r--svtools/inc/vclxaccessibleheaderbaritem.hxx1
-rw-r--r--svtools/source/contnr/imivctl.hxx2
-rw-r--r--svtools/source/contnr/imivctl2.cxx14
-rw-r--r--svtools/source/control/vclxaccessibleheaderbaritem.cxx4
-rw-r--r--svx/inc/sdr/contact/viewobjectcontactofsdrmediaobj.hxx3
-rw-r--r--svx/source/sdr/contact/viewobjectcontactofsdrmediaobj.cxx4
-rw-r--r--sw/source/core/doc/DocumentLayoutManager.cxx8
-rw-r--r--sw/source/core/doc/DocumentListItemsManager.cxx3
-rw-r--r--sw/source/core/inc/DocumentLayoutManager.hxx3
-rw-r--r--sw/source/core/inc/DocumentListItemsManager.hxx3
-rw-r--r--sw/source/filter/ww8/wrtww8.cxx2
-rw-r--r--sw/source/filter/ww8/wrtww8.hxx2
-rw-r--r--unotools/source/config/options.cxx7
-rw-r--r--vcl/source/control/field2.cxx7
37 files changed, 121 insertions, 101 deletions
diff --git a/chart2/source/view/axes/VPolarAngleAxis.cxx b/chart2/source/view/axes/VPolarAngleAxis.cxx
index c5d6b62ded37..9186a4643c6b 100644
--- a/chart2/source/view/axes/VPolarAngleAxis.cxx
+++ b/chart2/source/view/axes/VPolarAngleAxis.cxx
@@ -44,8 +44,6 @@ VPolarAngleAxis::VPolarAngleAxis( const AxisProperties& rAxisProperties
VPolarAngleAxis::~VPolarAngleAxis()
{
- delete m_pPosHelper;
- m_pPosHelper = nullptr;
}
bool VPolarAngleAxis::createTextShapes_ForAngleAxis(
@@ -118,7 +116,7 @@ bool VPolarAngleAxis::createTextShapes_ForAngleAxis(
double fLogicAngle = pTickInfo->getUnscaledTickValue();
LabelAlignment eLabelAlignment(LABEL_ALIGN_CENTER);
- PolarLabelPositionHelper aPolarLabelPositionHelper(m_pPosHelper,nDimensionCount,xTarget, pShapeFactory);
+ PolarLabelPositionHelper aPolarLabelPositionHelper(m_pPosHelper.get(), nDimensionCount, xTarget, pShapeFactory);
sal_Int32 nScreenValueOffsetInRadiusDirection = m_aAxisLabelProperties.m_aMaximumSpaceForLabels.Height/15;
awt::Point aAnchorScreenPosition2D( aPolarLabelPositionHelper.getLabelScreenPositionAndAlignmentForLogicValues(
eLabelAlignment, fLogicAngle, fLogicRadius, fLogicZ, nScreenValueOffsetInRadiusDirection ));
@@ -201,7 +199,7 @@ void VPolarAngleAxis::createShapes()
//create axis main lines
drawing::PointSequenceSequence aPoints(1);
- VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints, m_aAllTickInfos, m_aIncrement, m_aScale, m_pPosHelper, fLogicRadius, fLogicZ );
+ VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints, m_aAllTickInfos, m_aIncrement, m_aScale, m_pPosHelper.get(), fLogicRadius, fLogicZ );
uno::Reference< drawing::XShape > xShape = m_pShapeFactory->createLine2D(
m_xGroupShape_Shapes, aPoints, &m_aAxisProperties.m_aLineProperties );
//because of this name this line will be used for marking the axis
diff --git a/chart2/source/view/axes/VPolarAxis.cxx b/chart2/source/view/axes/VPolarAxis.cxx
index c7783d8e087e..da53f99b527c 100644
--- a/chart2/source/view/axes/VPolarAxis.cxx
+++ b/chart2/source/view/axes/VPolarAxis.cxx
@@ -45,13 +45,11 @@ VPolarAxis::VPolarAxis( const AxisProperties& rAxisProperties
, m_pPosHelper( new PolarPlottingPositionHelper() )
, m_aIncrements()
{
- PlotterBase::m_pPosHelper = m_pPosHelper;
+ PlotterBase::m_pPosHelper = m_pPosHelper.get();
}
VPolarAxis::~VPolarAxis()
{
- delete m_pPosHelper;
- m_pPosHelper = nullptr;
}
void VPolarAxis::setIncrements( const std::vector< ExplicitIncrementData >& rIncrements )
diff --git a/chart2/source/view/axes/VPolarAxis.hxx b/chart2/source/view/axes/VPolarAxis.hxx
index 1ce1b3c94add..f1626f4b9474 100644
--- a/chart2/source/view/axes/VPolarAxis.hxx
+++ b/chart2/source/view/axes/VPolarAxis.hxx
@@ -20,6 +20,7 @@
#define INCLUDED_CHART2_SOURCE_VIEW_AXES_VPOLARAXIS_HXX
#include "VAxisBase.hxx"
+#include <memory>
namespace chart
{
@@ -45,7 +46,7 @@ protected:
, sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount );
protected: //member
- PolarPlottingPositionHelper* m_pPosHelper;
+ std::unique_ptr<PolarPlottingPositionHelper> m_pPosHelper;
std::vector< ExplicitIncrementData > m_aIncrements;
};
diff --git a/chart2/source/view/axes/VPolarGrid.cxx b/chart2/source/view/axes/VPolarGrid.cxx
index 6347900a167e..7ff9a9be2ffd 100644
--- a/chart2/source/view/axes/VPolarGrid.cxx
+++ b/chart2/source/view/axes/VPolarGrid.cxx
@@ -43,13 +43,11 @@ VPolarGrid::VPolarGrid( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount
, m_pPosHelper( new PolarPlottingPositionHelper() )
, m_aIncrements()
{
- PlotterBase::m_pPosHelper = m_pPosHelper;
+ PlotterBase::m_pPosHelper = m_pPosHelper.get();
}
VPolarGrid::~VPolarGrid()
{
- delete m_pPosHelper;
- m_pPosHelper = nullptr;
}
void VPolarGrid::setIncrements( const std::vector< ExplicitIncrementData >& rIncrements )
@@ -207,7 +205,7 @@ void VPolarGrid::create2DRadiusGrid( const Reference< drawing::XShapes >& xLogic
drawing::PointSequenceSequence aPoints(1);
VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints, rAngleTickInfos
- , rAngleIncrement, rAngleScale, m_pPosHelper, fLogicRadius, fLogicZ );
+ , rAngleIncrement, rAngleScale, m_pPosHelper.get(), fLogicRadius, fLogicZ );
if(aPoints[0].getLength())
appendPointSequence( aAllPoints, aPoints );
}
diff --git a/chart2/source/view/axes/VPolarGrid.hxx b/chart2/source/view/axes/VPolarGrid.hxx
index ab7326607ce7..f7c177071567 100644
--- a/chart2/source/view/axes/VPolarGrid.hxx
+++ b/chart2/source/view/axes/VPolarGrid.hxx
@@ -23,6 +23,7 @@
#include "Tickmarks.hxx"
#include "VLineProperties.hxx"
#include <com/sun/star/drawing/PointSequenceSequence.hpp>
+#include <memory>
namespace chart
{
@@ -54,7 +55,7 @@ public:
private: //member
css::uno::Sequence<
css::uno::Reference< css::beans::XPropertySet > > m_aGridPropertiesList;//main grid, subgrid, subsubgrid etc
- PolarPlottingPositionHelper* m_pPosHelper;
+ std::unique_ptr<PolarPlottingPositionHelper> m_pPosHelper;
std::vector< ExplicitIncrementData > m_aIncrements;
void getAllTickInfos( sal_Int32 nDimensionIndex, TickInfoArraysType& rAllTickInfos ) const;
diff --git a/chart2/source/view/axes/VPolarRadiusAxis.cxx b/chart2/source/view/axes/VPolarRadiusAxis.cxx
index d05c2f4b7e72..ffc66d3e2842 100644
--- a/chart2/source/view/axes/VPolarRadiusAxis.cxx
+++ b/chart2/source/view/axes/VPolarRadiusAxis.cxx
@@ -48,8 +48,6 @@ VPolarRadiusAxis::VPolarRadiusAxis( const AxisProperties& rAxisProperties
VPolarRadiusAxis::~VPolarRadiusAxis()
{
- delete m_pPosHelper;
- m_pPosHelper = nullptr;
}
void VPolarRadiusAxis::setTransformationSceneToScreen( const drawing::HomogenMatrix& rMatrix)
diff --git a/compilerplugins/clang/test/useuniqueptr.cxx b/compilerplugins/clang/test/useuniqueptr.cxx
new file mode 100644
index 000000000000..c705bbf0f158
--- /dev/null
+++ b/compilerplugins/clang/test/useuniqueptr.cxx
@@ -0,0 +1,20 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+
+class Foo {
+ char* m_pbar; // expected-note {{member is here [loplugin:useuniqueptr]}}
+ ~Foo() // expected-error {{Unreferenced externally visible function definition [loplugin:unreffun]}}
+ {
+ delete m_pbar; // expected-error {{a destructor with only a single unconditional call to delete on a member, is a sure sign it should be using std::unique_ptr for that field [loplugin:useuniqueptr]}}
+ m_pbar = 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 59d1a3f3ec68..afae4c3c770a 100644
--- a/compilerplugins/clang/useuniqueptr.cxx
+++ b/compilerplugins/clang/useuniqueptr.cxx
@@ -44,30 +44,32 @@ bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDec
if (isInUnoIncludeFile(destructorDecl))
return true;
- if (destructorDecl->getBody() == nullptr)
+ const CompoundStmt* compoundStmt = dyn_cast_or_null< CompoundStmt >( destructorDecl->getBody() );
+ if (!compoundStmt)
return true;
- const CompoundStmt* compoundStmt = dyn_cast< CompoundStmt >( destructorDecl->getBody() );
- if (compoundStmt == nullptr) {
- return true;
- }
- const CXXDeleteExpr* deleteExpr;
+ const CXXDeleteExpr* deleteExpr = nullptr;
if (compoundStmt->size() == 1) {
deleteExpr = dyn_cast<CXXDeleteExpr>(compoundStmt->body_front());
}
else if (compoundStmt->size() == 2) {
// ignore SAL_INFO type stuff
- // TODO should probably be a little more specific here
- if (!isa<DoStmt>(compoundStmt->body_front())) {
- return true;
+ // @TODO should probably be a little more specific here
+ if (isa<DoStmt>(compoundStmt->body_front())) {
+ deleteExpr = dyn_cast<CXXDeleteExpr>(compoundStmt->body_back());
+ }
+ // look for the following pattern:
+ // delete m_pbar;
+ // m_pbar = nullptr;
+ else if (auto binaryOp = dyn_cast<BinaryOperator>(compoundStmt->body_back())) {
+ if (binaryOp->getOpcode() == BO_Assign)
+ deleteExpr = dyn_cast<CXXDeleteExpr>(compoundStmt->body_front());
}
- deleteExpr = dyn_cast<CXXDeleteExpr>(compoundStmt->body_back());
} else {
return true;
}
- if (deleteExpr == nullptr) {
+ if (deleteExpr == nullptr)
return true;
- }
const ImplicitCastExpr* pCastExpr = dyn_cast<ImplicitCastExpr>(deleteExpr->getArgument());
if (!pCastExpr)
diff --git a/forms/source/component/propertybaghelper.cxx b/forms/source/component/propertybaghelper.cxx
index ab73d42b575d..49a10ee95a99 100644
--- a/forms/source/component/propertybaghelper.cxx
+++ b/forms/source/component/propertybaghelper.cxx
@@ -80,8 +80,6 @@ namespace frm
PropertyBagHelper::~PropertyBagHelper()
{
- delete m_pPropertyArrayHelper;
- m_pPropertyArrayHelper = nullptr;
}
@@ -100,8 +98,7 @@ namespace frm
void PropertyBagHelper::impl_nts_invalidatePropertySetInfo()
{
- delete m_pPropertyArrayHelper;
- m_pPropertyArrayHelper = nullptr;
+ m_pPropertyArrayHelper.reset();
}
@@ -146,11 +143,11 @@ namespace frm
::comphelper::OPropertyArrayAggregationHelper& PropertyBagHelper::impl_ts_getArrayHelper() const
{
- OPropertyArrayAggregationHelper* p = m_pPropertyArrayHelper;
+ OPropertyArrayAggregationHelper* p = m_pPropertyArrayHelper.get();
if ( !p )
{
::osl::MutexGuard aGuard( m_rContext.getMutex() );
- p = m_pPropertyArrayHelper;
+ p = m_pPropertyArrayHelper.get();
if ( !p )
{
// our own fixed and our aggregate's properties
@@ -167,7 +164,7 @@ namespace frm
p = new OPropertyArrayAggregationHelper( aOwnProps, aAggregateProps, &lcl_getPropertyInfos(), NEW_HANDLE_BASE );
OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
- const_cast< PropertyBagHelper* >( this )->m_pPropertyArrayHelper = p;
+ const_cast< PropertyBagHelper* >( this )->m_pPropertyArrayHelper.reset( p );
}
} // if ( !p )
else
diff --git a/forms/source/inc/propertybaghelper.hxx b/forms/source/inc/propertybaghelper.hxx
index f4ca932704ef..e3d86b3673a7 100644
--- a/forms/source/inc/propertybaghelper.hxx
+++ b/forms/source/inc/propertybaghelper.hxx
@@ -24,6 +24,7 @@
#include <comphelper/propertybag.hxx>
#include <comphelper/propagg.hxx>
+#include <memory>
namespace frm
@@ -53,7 +54,8 @@ namespace frm
{
private:
IPropertyBagHelperContext& m_rContext;
- ::comphelper::OPropertyArrayAggregationHelper* m_pPropertyArrayHelper;
+ std::unique_ptr<::comphelper::OPropertyArrayAggregationHelper>
+ m_pPropertyArrayHelper;
::comphelper::PropertyBag m_aDynamicProperties;
bool m_bDisposed;
diff --git a/hwpfilter/source/hinfo.cxx b/hwpfilter/source/hinfo.cxx
index 2e5d4b1c9a16..3d262b5c7d1e 100644
--- a/hwpfilter/source/hinfo.cxx
+++ b/hwpfilter/source/hinfo.cxx
@@ -66,8 +66,6 @@ HWPInfo::HWPInfo()
HWPInfo::~HWPInfo()
{
- delete[] info_block;
- info_block = nullptr;
}
@@ -163,9 +161,9 @@ void HWPInfo::Read(HWPFile & hwpf)
return;
if (info_block_len > 0)
{
- info_block = new unsigned char[info_block_len + 1];
+ info_block.reset( new unsigned char[info_block_len + 1] );
- if (!HWPReadInfoBlock(info_block, info_block_len, hwpf))
+ if (!HWPReadInfoBlock(info_block.get(), info_block_len, hwpf))
return;
}
diff --git a/hwpfilter/source/hinfo.h b/hwpfilter/source/hinfo.h
index 7f1eee0657c7..a381cc1dfb59 100644
--- a/hwpfilter/source/hinfo.h
+++ b/hwpfilter/source/hinfo.h
@@ -24,6 +24,7 @@
#include "string.h"
#include <vector>
+#include <memory>
#define CHAIN_MAX_PATH 40
#define ANNOTATION_LEN 24
@@ -201,7 +202,7 @@ class DLLEXPORT HWPInfo
* Summary of document
*/
HWPSummary summary;
- unsigned char *info_block;
+ std::unique_ptr<unsigned char[]> info_block;
HWPInfo(void);
~HWPInfo(void);
diff --git a/include/sfx2/sfxbasemodel.hxx b/include/sfx2/sfxbasemodel.hxx
index 1188bef60028..c8cb5783cf99 100644
--- a/include/sfx2/sfxbasemodel.hxx
+++ b/include/sfx2/sfxbasemodel.hxx
@@ -87,6 +87,8 @@
#include <cppuhelper/implbase.hxx>
#include <svl/lstner.hxx>
+#include <memory>
+
class SfxMedium;
class SfxPrinter;
class SfxViewShell;
@@ -738,7 +740,7 @@ private:
private:
- IMPL_SfxBaseModel_DataContainer* m_pData ;
+ std::unique_ptr<IMPL_SfxBaseModel_DataContainer> m_pData;
// cannot be held in m_pData, since it needs to be accessed in non-threadsafe context
const bool m_bSupportEmbeddedScripts;
const bool m_bSupportDocRecovery;
diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx
index 78ed4120841f..eae64a52388c 100644
--- a/include/svl/poolitem.hxx
+++ b/include/svl/poolitem.hxx
@@ -23,6 +23,7 @@
#include <sal/config.h>
#include <climits>
+#include <memory>
#include <com/sun/star/uno/Any.hxx>
#include <svl/hint.hxx>
@@ -256,7 +257,7 @@ public:
class SVL_DLLPUBLIC SfxSetItem: public SfxPoolItem
{
- SfxItemSet *pSet;
+ std::unique_ptr<SfxItemSet> pSet;
SfxSetItem & operator=( const SfxSetItem& ) = delete;
diff --git a/include/unotools/options.hxx b/include/unotools/options.hxx
index 08773f4f53c4..c2316aacf940 100644
--- a/include/unotools/options.hxx
+++ b/include/unotools/options.hxx
@@ -78,6 +78,7 @@ namespace utl {
// notify listeners; nHint is an implementation detail of the particular class deriving from ConfigurationBroadcaster
void NotifyListeners( ConfigurationHints nHint );
ConfigurationBroadcaster();
+ ConfigurationBroadcaster(ConfigurationBroadcaster const & );
virtual ~ConfigurationBroadcaster();
virtual void BlockBroadcasts( bool bBlock );
};
diff --git a/include/vcl/field.hxx b/include/vcl/field.hxx
index 763fe714d9f0..7fca5c290205 100644
--- a/include/vcl/field.hxx
+++ b/include/vcl/field.hxx
@@ -269,7 +269,7 @@ public:
class VCL_DLLPUBLIC DateFormatter : public FormatterBase
{
private:
- CalendarWrapper* mpCalendarWrapper;
+ std::unique_ptr<CalendarWrapper> mpCalendarWrapper;
Date maFieldDate;
Date maLastDate;
Date maMin;
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index cfd5affb0b8f..9e73783f1f28 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -33,6 +33,7 @@
#include <rtl/ustrbuf.hxx>
#include <com/sun/star/sheet/ExternalLinkInfo.hpp>
#include <vector>
+#include <memory>
#include <formula/FormulaCompiler.hxx>
#include <o3tl/typed_flags_set.hxx>
@@ -244,7 +245,7 @@ public:
virtual ScCharFlags getCharTableFlags( sal_Unicode c, sal_Unicode cLast ) const = 0;
protected:
- const ScCharFlags* mpCharTable;
+ std::unique_ptr<ScCharFlags[]> mpCharTable;
};
friend struct Convention;
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 8e552a878f81..e8af73691b29 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -290,8 +290,6 @@ OUString ScCompiler::FindAddInFunction( const OUString& rUpperName, bool bLocalF
ScCompiler::Convention::~Convention()
{
- delete [] mpCharTable;
- mpCharTable = nullptr;
}
ScCompiler::Convention::Convention( FormulaGrammar::AddressConvention eConv )
@@ -302,7 +300,7 @@ ScCompiler::Convention::Convention( FormulaGrammar::AddressConvention eConv )
ScCharFlags *t= new ScCharFlags [128];
ScCompiler::pConventions[ meConv ] = this;
- mpCharTable = t;
+ mpCharTable.reset( t );
for (i = 0; i < 128; i++)
t[i] = ScCharFlags::Illegal;
diff --git a/sd/source/ui/app/optsitem.cxx b/sd/source/ui/app/optsitem.cxx
index cdbcacd330e4..f23f1fbc6059 100644
--- a/sd/source/ui/app/optsitem.cxx
+++ b/sd/source/ui/app/optsitem.cxx
@@ -86,6 +86,21 @@ SdOptionsGeneric::SdOptionsGeneric(sal_uInt16 nConfigId, const OUString& rSubTre
{
}
+SdOptionsGeneric::SdOptionsGeneric(SdOptionsGeneric const & rSource)
+{
+ operator=(rSource);
+}
+
+SdOptionsGeneric& SdOptionsGeneric::operator=(SdOptionsGeneric const & rSource)
+{
+ maSubTree = rSource.maSubTree;
+ mpCfgItem.reset(rSource.mpCfgItem ? new SdOptionsItem(*rSource.mpCfgItem) : nullptr );
+ mnConfigId = rSource.mnConfigId;
+ mbInit = rSource.mbInit;
+ mbEnableModify = rSource.mbEnableModify;
+ return *this;
+}
+
void SdOptionsGeneric::Init() const
{
if( !mbInit )
@@ -93,7 +108,7 @@ void SdOptionsGeneric::Init() const
SdOptionsGeneric* pThis = const_cast<SdOptionsGeneric*>(this);
if( !mpCfgItem )
- pThis->mpCfgItem = new SdOptionsItem( *this, maSubTree );
+ pThis->mpCfgItem.reset( new SdOptionsItem( *this, maSubTree ) );
const Sequence< OUString > aNames( GetPropertyNames() );
const Sequence< Any > aValues = mpCfgItem->GetProperties( aNames );
@@ -113,8 +128,6 @@ void SdOptionsGeneric::Init() const
SdOptionsGeneric::~SdOptionsGeneric()
{
- delete mpCfgItem;
- mpCfgItem = nullptr;
}
void SdOptionsGeneric::Commit( SdOptionsItem& rCfgItem ) const
diff --git a/sd/source/ui/inc/optsitem.hxx b/sd/source/ui/inc/optsitem.hxx
index 5bf26e738eff..5ff8e4cf7e81 100644
--- a/sd/source/ui/inc/optsitem.hxx
+++ b/sd/source/ui/inc/optsitem.hxx
@@ -27,6 +27,7 @@
#include <svx/optgrid.hxx>
#include <svx/dlgutil.hxx>
#include "sddllapi.h"
+#include <memory>
class SdOptions;
@@ -65,7 +66,8 @@ friend class SdOptionsItem;
private:
OUString maSubTree;
- SdOptionsItem* mpCfgItem;
+ std::unique_ptr<SdOptionsItem>
+ mpCfgItem;
sal_uInt16 mnConfigId;
bool mbInit : 1;
bool mbEnableModify : 1;
@@ -87,8 +89,11 @@ protected:
public:
SdOptionsGeneric( sal_uInt16 nConfigId, const OUString& rSubTree );
+ SdOptionsGeneric( SdOptionsGeneric const & );
virtual ~SdOptionsGeneric();
+ SdOptionsGeneric& operator=( SdOptionsGeneric const & );
+
sal_uInt16 GetConfigId() const { return mnConfigId; }
void EnableModify( bool bModify ) { mbEnableModify = bModify; }
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index 39743b8b83b5..c3cbdb3712ca 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -500,10 +500,6 @@ SfxBaseModel::SfxBaseModel( SfxObjectShell *pObjectShell )
// destructor
SfxBaseModel::~SfxBaseModel()
{
- //In SvxDrawingLayerImport when !xTargetDocument the fallback SvxUnoDrawingModel created there
- //never gets disposed called on it, so m_pData leaks.
- delete m_pData;
- m_pData = nullptr;
}
// XInterface
@@ -760,12 +756,10 @@ void SAL_CALL SfxBaseModel::dispose()
m_pData->m_xCurrent.clear();
m_pData->m_seqControllers.clear();
- // m_pData member must be set to zero before 0delete is called to
+ // m_pData member must be set to zero before delete is called to
// force disposed exception whenever someone tries to access our
// instance while in the dtor.
- IMPL_SfxBaseModel_DataContainer* pData = m_pData;
- m_pData = nullptr;
- delete pData;
+ m_pData.reset();
}
@@ -1471,7 +1465,7 @@ void SAL_CALL SfxBaseModel::storeSelf( const Sequence< beans::PropertyValue >
if ( m_pData->m_pObjectShell.is() )
{
- SfxSaveGuard aSaveGuard(this, m_pData);
+ SfxSaveGuard aSaveGuard(this, m_pData.get());
bool bCheckIn = false;
for ( sal_Int32 nInd = 0; nInd < aSeqArgs.getLength(); nInd++ )
@@ -1592,7 +1586,7 @@ void SAL_CALL SfxBaseModel::storeAsURL( const OUString& rURL
if ( m_pData->m_pObjectShell.is() )
{
- SfxSaveGuard aSaveGuard(this, m_pData);
+ SfxSaveGuard aSaveGuard(this, m_pData.get());
impl_store( rURL, rArgs, false );
@@ -1631,7 +1625,7 @@ void SAL_CALL SfxBaseModel::storeToURL( const OUString& rURL
if ( m_pData->m_pObjectShell.is() )
{
- SfxSaveGuard aSaveGuard(this, m_pData);
+ SfxSaveGuard aSaveGuard(this, m_pData.get());
try {
impl_store(rURL, rArgs, true);
}
@@ -1656,7 +1650,7 @@ void SAL_CALL SfxBaseModel::storeToRecoveryFile( const OUString& i_TargetLocatio
SfxModelGuard aGuard( *this );
// delegate
- SfxSaveGuard aSaveGuard( this, m_pData );
+ SfxSaveGuard aSaveGuard( this, m_pData.get() );
impl_store( i_TargetLocation, i_MediaDescriptor, true );
// no need for subsequent calls to storeToRecoveryFile, unless we're modified, again
@@ -3750,7 +3744,7 @@ bool SfxBaseModel::impl_getPrintHelper()
aValues[0] <<= Reference < frame::XModel > (static_cast< frame::XModel* >(this), UNO_QUERY );
xInit->initialize( aValues );
Reference < view::XPrintJobBroadcaster > xBrd( m_pData->m_xPrintable, UNO_QUERY );
- xBrd->addPrintJobListener( new SfxPrintHelperListener_Impl( m_pData ) );
+ xBrd->addPrintJobListener( new SfxPrintHelperListener_Impl( m_pData.get() ) );
return true;
}
diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk
index dd8951325e50..d85ba6d9f58e 100644
--- a/solenv/CompilerTest_compilerplugins_clang.mk
+++ b/solenv/CompilerTest_compilerplugins_clang.mk
@@ -27,6 +27,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/stringcopy \
compilerplugins/clang/test/unnecessaryoverride-dtor \
compilerplugins/clang/test/unoany \
+ compilerplugins/clang/test/useuniqueptr \
compilerplugins/clang/test/vclwidgets \
))
diff --git a/svl/source/items/sitem.cxx b/svl/source/items/sitem.cxx
index 1947f7e99b79..0ea270fc9980 100644
--- a/svl/source/items/sitem.cxx
+++ b/svl/source/items/sitem.cxx
@@ -46,7 +46,6 @@ SfxSetItem::SfxSetItem( const SfxSetItem& rCopy, SfxItemPool *pPool ) :
SfxSetItem::~SfxSetItem()
{
- delete pSet; pSet = nullptr;
}
diff --git a/svtools/inc/vclxaccessibleheaderbaritem.hxx b/svtools/inc/vclxaccessibleheaderbaritem.hxx
index 5bdb0ac7de46..e3732f11e3c0 100644
--- a/svtools/inc/vclxaccessibleheaderbaritem.hxx
+++ b/svtools/inc/vclxaccessibleheaderbaritem.hxx
@@ -51,7 +51,6 @@ class VCLXAccessibleHeaderBarItem : public comphelper::OAccessibleExtendedCom
public VCLXAccessibleHeaderBarItem_BASE
{
private:
- VCLExternalSolarLock* m_pExternalLock;
VclPtr<HeaderBar> m_pHeadBar;
sal_Int32 m_nIndexInParent;
diff --git a/svtools/source/contnr/imivctl.hxx b/svtools/source/contnr/imivctl.hxx
index 7faf1a707fcd..fc3ccafceaa1 100644
--- a/svtools/source/contnr/imivctl.hxx
+++ b/svtools/source/contnr/imivctl.hxx
@@ -536,7 +536,7 @@ class IcnGridMap_Impl
{
tools::Rectangle _aLastOccupiedGrid;
SvxIconChoiceCtrl_Impl* _pView;
- bool * _pGridMap;
+ std::unique_ptr<bool[]> _pGridMap;
sal_uInt16 _nGridCols, _nGridRows;
void Expand();
diff --git a/svtools/source/contnr/imivctl2.cxx b/svtools/source/contnr/imivctl2.cxx
index 8fc65811fe35..ae2532edd7dd 100644
--- a/svtools/source/contnr/imivctl2.cxx
+++ b/svtools/source/contnr/imivctl2.cxx
@@ -483,8 +483,6 @@ IcnGridMap_Impl::IcnGridMap_Impl(SvxIconChoiceCtrl_Impl* pView)
IcnGridMap_Impl::~IcnGridMap_Impl()
{
- delete[] _pGridMap;
- _pGridMap = nullptr;
}
void IcnGridMap_Impl::Expand()
@@ -503,10 +501,9 @@ void IcnGridMap_Impl::Expand()
size_t nNewCellCount = static_cast<size_t>(nNewGridRows) * nNewGridCols;
bool* pNewGridMap = new bool[nNewCellCount];
size_t nOldCellCount = static_cast<size_t>(_nGridRows) * _nGridCols;
- memcpy(pNewGridMap, _pGridMap, nOldCellCount * sizeof(bool));
+ memcpy(pNewGridMap, _pGridMap.get(), nOldCellCount * sizeof(bool));
memset(pNewGridMap + nOldCellCount, 0, (nNewCellCount-nOldCellCount) * sizeof(bool));
- delete[] _pGridMap;
- _pGridMap = pNewGridMap;
+ _pGridMap.reset( pNewGridMap );
_nGridRows = nNewGridRows;
_nGridCols = nNewGridCols;
}
@@ -524,8 +521,8 @@ void IcnGridMap_Impl::Create_Impl()
_nGridCols += 50;
size_t nCellCount = static_cast<size_t>(_nGridRows) * _nGridCols;
- _pGridMap = new bool[nCellCount];
- memset(_pGridMap, 0, nCellCount * sizeof(bool));
+ _pGridMap.reset( new bool[nCellCount] );
+ memset(_pGridMap.get(), 0, nCellCount * sizeof(bool));
const size_t nCount = _pView->aEntries.size();
for( size_t nCur=0; nCur < nCount; nCur++ )
@@ -659,8 +656,7 @@ void IcnGridMap_Impl::Clear()
{
if( _pGridMap )
{
- delete[] _pGridMap;
- _pGridMap = nullptr;
+ _pGridMap.reset();
_nGridRows = 0;
_nGridCols = 0;
_aLastOccupiedGrid.SetEmpty();
diff --git a/svtools/source/control/vclxaccessibleheaderbaritem.cxx b/svtools/source/control/vclxaccessibleheaderbaritem.cxx
index 2cba759d59a9..fe839a073c3f 100644
--- a/svtools/source/control/vclxaccessibleheaderbaritem.cxx
+++ b/svtools/source/control/vclxaccessibleheaderbaritem.cxx
@@ -52,13 +52,11 @@ VCLXAccessibleHeaderBarItem::VCLXAccessibleHeaderBarItem( HeaderBar* pHeadBar
,m_nIndexInParent(_nIndexInParent + 1)
{
- m_pExternalLock = static_cast< VCLExternalSolarLock* >( getExternalLock() );
}
VCLXAccessibleHeaderBarItem::~VCLXAccessibleHeaderBarItem()
{
- delete m_pExternalLock;
- m_pExternalLock = nullptr;
+ delete static_cast< VCLExternalSolarLock* >( getExternalLock() );
}
void VCLXAccessibleHeaderBarItem::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
diff --git a/svx/inc/sdr/contact/viewobjectcontactofsdrmediaobj.hxx b/svx/inc/sdr/contact/viewobjectcontactofsdrmediaobj.hxx
index efe62f09f7c2..76eaeaa128da 100644
--- a/svx/inc/sdr/contact/viewobjectcontactofsdrmediaobj.hxx
+++ b/svx/inc/sdr/contact/viewobjectcontactofsdrmediaobj.hxx
@@ -23,6 +23,7 @@
#include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
#include <svx/sdr/contact/viewobjectcontact.hxx>
#include <tools/gen.hxx>
+#include <memory>
namespace avmedia { class MediaItem; }
namespace vcl { class Window; }
@@ -53,7 +54,7 @@ namespace sdr
private:
- sdr::contact::SdrMediaWindow* mpMediaWindow;
+ std::unique_ptr<sdr::contact::SdrMediaWindow> mpMediaWindow;
};
} // end of namespace contact
diff --git a/svx/source/sdr/contact/viewobjectcontactofsdrmediaobj.cxx b/svx/source/sdr/contact/viewobjectcontactofsdrmediaobj.cxx
index a239c3b303e3..46f4378f7f52 100644
--- a/svx/source/sdr/contact/viewobjectcontactofsdrmediaobj.cxx
+++ b/svx/source/sdr/contact/viewobjectcontactofsdrmediaobj.cxx
@@ -43,7 +43,7 @@ ViewObjectContactOfSdrMediaObj::ViewObjectContactOfSdrMediaObj( ObjectContact& r
if( pWindow )
{
- mpMediaWindow = new SdrMediaWindow( pWindow, *this );
+ mpMediaWindow.reset( new SdrMediaWindow( pWindow, *this ) );
mpMediaWindow->hide();
executeMediaItem( rMediaItem );
}
@@ -54,8 +54,6 @@ ViewObjectContactOfSdrMediaObj::ViewObjectContactOfSdrMediaObj( ObjectContact& r
ViewObjectContactOfSdrMediaObj::~ViewObjectContactOfSdrMediaObj()
{
- delete mpMediaWindow;
- mpMediaWindow = nullptr;
}
diff --git a/sw/source/core/doc/DocumentLayoutManager.cxx b/sw/source/core/doc/DocumentLayoutManager.cxx
index 7c3589a156dd..c54947739ddb 100644
--- a/sw/source/core/doc/DocumentLayoutManager.cxx
+++ b/sw/source/core/doc/DocumentLayoutManager.cxx
@@ -90,17 +90,17 @@ bool DocumentLayoutManager::HasLayout() const
SwLayouter* DocumentLayoutManager::GetLayouter()
{
- return mpLayouter;
+ return mpLayouter.get();
}
const SwLayouter* DocumentLayoutManager::GetLayouter() const
{
- return mpLayouter;
+ return mpLayouter.get();
}
void DocumentLayoutManager::SetLayouter( SwLayouter* pNew )
{
- mpLayouter = pNew;
+ mpLayouter.reset( pNew );
}
/** Create a new format whose settings fit to the Request by default.
@@ -508,8 +508,6 @@ void DocumentLayoutManager::ClearSwLayouterEntries()
DocumentLayoutManager::~DocumentLayoutManager()
{
- delete mpLayouter;
- mpLayouter = nullptr;
}
}
diff --git a/sw/source/core/doc/DocumentListItemsManager.cxx b/sw/source/core/doc/DocumentListItemsManager.cxx
index 43c05b8716b2..adbdeec36088 100644
--- a/sw/source/core/doc/DocumentListItemsManager.cxx
+++ b/sw/source/core/doc/DocumentListItemsManager.cxx
@@ -94,9 +94,6 @@ void DocumentListItemsManager::getNumItems( tSortedNodeNumList& orNodeNumList )
DocumentListItemsManager::~DocumentListItemsManager()
{
-// #i83479#
-delete mpListItemsList;
-mpListItemsList = nullptr;
}
diff --git a/sw/source/core/inc/DocumentLayoutManager.hxx b/sw/source/core/inc/DocumentLayoutManager.hxx
index 780ca1ff988e..c9813dbf819a 100644
--- a/sw/source/core/inc/DocumentLayoutManager.hxx
+++ b/sw/source/core/inc/DocumentLayoutManager.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_SW_SOURCE_CORE_INC_DOCUMENTLAYOUTMANAGER_HXX
#include <IDocumentLayoutAccess.hxx>
+#include <memory>
class SwDoc;
class SwViewShell;
@@ -64,7 +65,7 @@ private:
SwDoc& m_rDoc;
SwViewShell *mpCurrentView; //< SwDoc should get a new member mpCurrentView
- SwLayouter *mpLayouter; /**< css::frame::Controller for complex layout formatting
+ std::unique_ptr<SwLayouter> mpLayouter; /**< css::frame::Controller for complex layout formatting
like footnote/endnote in sections */
};
diff --git a/sw/source/core/inc/DocumentListItemsManager.hxx b/sw/source/core/inc/DocumentListItemsManager.hxx
index b4b3d3dc15d1..36e56e015d7a 100644
--- a/sw/source/core/inc/DocumentListItemsManager.hxx
+++ b/sw/source/core/inc/DocumentListItemsManager.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_SW_SOURCE_CORE_INC_DOCUMENTLISTITEMSMANAGER_HXX
#include <IDocumentListItems.hxx>
+#include <memory>
#include <set>
namespace sw
@@ -56,7 +57,7 @@ private:
DocumentListItemsManager(DocumentListItemsManager const&) = delete;
DocumentListItemsManager& operator=(DocumentListItemsManager const&) = delete;
- tImplSortedNodeNumList* mpListItemsList;
+ std::unique_ptr<tImplSortedNodeNumList> mpListItemsList;
};
}
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 3fe6385e7d3d..2d6320387f09 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -3596,8 +3596,6 @@ WW8Export::WW8Export( SwWW8Writer *pWriter,
WW8Export::~WW8Export()
{
- delete m_pAttrOutput;
- m_pAttrOutput = nullptr;
}
AttributeOutputBase& WW8Export::AttrOutput() const
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index abe3475636a4..0957e33220fd 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -959,7 +959,7 @@ public:
protected:
SwWW8Writer *m_pWriter; ///< Pointer to the writer
- WW8AttributeOutput *m_pAttrOutput; ///< Converting attributes to stream data
+ std::unique_ptr<WW8AttributeOutput> m_pAttrOutput; ///< Converting attributes to stream data
private:
tools::SvRef<SotStorage> xEscherStg; /// memory leak #i120098#, to hold the reference to unnamed SotStorage obj
diff --git a/unotools/source/config/options.cxx b/unotools/source/config/options.cxx
index d3f70ec8cb73..593c431580d2 100644
--- a/unotools/source/config/options.cxx
+++ b/unotools/source/config/options.cxx
@@ -32,6 +32,13 @@ ConfigurationBroadcaster::ConfigurationBroadcaster()
{
}
+ConfigurationBroadcaster::ConfigurationBroadcaster(ConfigurationBroadcaster const & rSource)
+: mpList( rSource.mpList ? new IMPL_ConfigurationListenerList(*rSource.mpList) : nullptr )
+, m_nBroadcastBlocked( rSource.m_nBroadcastBlocked )
+, m_nBlockedHint( rSource.m_nBlockedHint )
+{
+}
+
ConfigurationBroadcaster::~ConfigurationBroadcaster()
{
}
diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx
index dc36c0526735..ac9bb2b16305 100644
--- a/vcl/source/control/field2.cxx
+++ b/vcl/source/control/field2.cxx
@@ -1426,14 +1426,11 @@ DateFormatter::DateFormatter() :
DateFormatter::~DateFormatter()
{
- delete mpCalendarWrapper;
- mpCalendarWrapper = nullptr;
}
void DateFormatter::SetLocale( const css::lang::Locale& rLocale )
{
- delete mpCalendarWrapper;
- mpCalendarWrapper = nullptr;
+ mpCalendarWrapper.reset();
FormatterBase::SetLocale( rLocale );
}
@@ -1441,7 +1438,7 @@ CalendarWrapper& DateFormatter::GetCalendarWrapper() const
{
if ( !mpCalendarWrapper )
{
- const_cast<DateFormatter*>(this)->mpCalendarWrapper = new CalendarWrapper( comphelper::getProcessComponentContext() );
+ const_cast<DateFormatter*>(this)->mpCalendarWrapper.reset( new CalendarWrapper( comphelper::getProcessComponentContext() ) );
mpCalendarWrapper->loadDefaultCalendar( GetLocale() );
}