summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-07-13 10:50:22 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-07-13 11:58:10 +0200
commitdbf8ad9bc385411c349095dfa66345464b4215d6 (patch)
tree507ac08bf144fa8ac44ad4889ce127cb0d0c70c7
parentb0e2dbca5164c494a669bd48f8ff058f4c1ad710 (diff)
loplugin:useuniqueptr in SbUnoStructRefObject
now that we have upgraded to VS2017, we can use std::unique_ptr in std::map Change-Id: Id01af07ccae7447405b8f0bc44b08043f453e54b Reviewed-on: https://gerrit.libreoffice.org/57384 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--basic/source/classes/sbunoobj.cxx5
-rw-r--r--basic/source/inc/sbunoobj.hxx2
-rw-r--r--compilerplugins/clang/test/useuniqueptr.cxx5
-rw-r--r--compilerplugins/clang/useuniqueptr.cxx3
4 files changed, 5 insertions, 10 deletions
diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx
index 5eda97d08856..ddf92c07638b 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <o3tl/any.hxx>
+#include <o3tl/make_unique.hxx>
#include <osl/mutex.hxx>
#include <vcl/svapp.hxx>
#include <vcl/errcode.hxx>
@@ -4636,8 +4637,6 @@ SbUnoStructRefObject::SbUnoStructRefObject( const OUString& aName_, const Struct
SbUnoStructRefObject::~SbUnoStructRefObject()
{
- for (auto const& field : maFields)
- delete field.second;
}
void SbUnoStructRefObject::initMemberCache()
@@ -4659,7 +4658,7 @@ void SbUnoStructRefObject::initMemberCache()
for ( sal_Int32 nPos = pCompTypeDescr->nMembers; nPos--; )
{
OUString aName( ppNames[nPos] );
- maFields[ aName ] = new StructRefInfo( maMemberInfo.getRootAnyRef(), ppTypeRefs[nPos], maMemberInfo.getPos() + pMemberOffsets[nPos] );
+ maFields[ aName ] = o3tl::make_unique<StructRefInfo>( maMemberInfo.getRootAnyRef(), ppTypeRefs[nPos], maMemberInfo.getPos() + pMemberOffsets[nPos] );
}
}
typelib_typedescription_release(pTD);
diff --git a/basic/source/inc/sbunoobj.hxx b/basic/source/inc/sbunoobj.hxx
index 2df319ffbb21..d9c654b77d23 100644
--- a/basic/source/inc/sbunoobj.hxx
+++ b/basic/source/inc/sbunoobj.hxx
@@ -71,7 +71,7 @@ class SbUnoStructRefObject: public SbxObject
return rProp.compareToIgnoreAsciiCase( rOtherProp ) < 0;
}
};
- typedef std::map< OUString, StructRefInfo*, caseLessComp > StructFieldInfo;
+ typedef std::map< OUString, std::unique_ptr<StructRefInfo>, caseLessComp > StructFieldInfo;
StructFieldInfo maFields;
StructRefInfo maMemberInfo;
bool mbMemberCacheInit;
diff --git a/compilerplugins/clang/test/useuniqueptr.cxx b/compilerplugins/clang/test/useuniqueptr.cxx
index c7c92313a5e6..24a34c0e54b9 100644
--- a/compilerplugins/clang/test/useuniqueptr.cxx
+++ b/compilerplugins/clang/test/useuniqueptr.cxx
@@ -77,13 +77,12 @@ class Class7 {
delete m_pbar[i]; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
}
};
-// don't warn for maps, MSVC 2015 has problems with mixing std::map/std::unordered_map and std::unique_ptr
class Class8 {
- std::unordered_map<int, int*> m_pbar;
+ std::unordered_map<int, int*> m_pbar; // expected-note {{member is here [loplugin:useuniqueptr]}}
~Class8()
{
for (auto i : m_pbar)
- delete i.second;
+ delete i.second; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
}
};
class Foo8 {
diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx
index 0af8cd295a6b..0520546052a4 100644
--- a/compilerplugins/clang/useuniqueptr.cxx
+++ b/compilerplugins/clang/useuniqueptr.cxx
@@ -288,10 +288,7 @@ void UseUniquePtr::CheckDeleteExpr(const CXXMethodDecl* methodDecl, const CXXDel
// the std::vector is being passed to another class
if (loplugin::isSamePathname(aFileName, SRCDIR "/sfx2/source/explorer/nochaos.cxx"))
return;
- // ignore std::map and std::unordered_map, MSVC 2015 has problems with mixing these with std::unique_ptr
auto tc = loplugin::TypeCheck(fieldDecl->getType());
- if (tc.Class("map").StdNamespace() || tc.Class("unordered_map").StdNamespace())
- return;
// these sw::Ring based classes do not lend themselves to std::unique_ptr management
if (tc.Pointer().Class("SwNodeIndex").GlobalNamespace() || tc.Pointer().Class("SwShellTableCursor").GlobalNamespace()
|| tc.Pointer().Class("SwBlockCursor").GlobalNamespace() || tc.Pointer().Class("SwVisibleCursor").GlobalNamespace()