Kaydet (Commit) dbf8ad9b authored tarafından Noel Grandin's avatar Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst b0e2dbca
......@@ -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);
......
......@@ -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;
......
......@@ -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 {
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment