[Libreoffice-commits] core.git: basic/source compilerplugins/clang
Noel Grandin
noel.grandin at collabora.co.uk
Fri Jul 13 09:58:35 UTC 2018
basic/source/classes/sbunoobj.cxx | 5 ++---
basic/source/inc/sbunoobj.hxx | 2 +-
compilerplugins/clang/test/useuniqueptr.cxx | 5 ++---
compilerplugins/clang/useuniqueptr.cxx | 3 ---
4 files changed, 5 insertions(+), 10 deletions(-)
New commits:
commit dbf8ad9bc385411c349095dfa66345464b4215d6
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Fri Jul 13 10:50:22 2018 +0200
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 at collabora.co.uk>
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()
More information about the Libreoffice-commits
mailing list