Kaydet (Commit) a9303d85 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Make brittle SortedAutoCompleteStrings ownership handling more explicit

Change-Id: Ieaf2231a84d97528bb1b9a410c4ee0c38966dd27
Reviewed-on: https://gerrit.libreoffice.org/56950
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 8d69ca2d
......@@ -23,4 +23,7 @@ Any change in this header will cause a rebuild of almost everything.
/* Compiler supports __attribute__((warn_unused)). */
#define HAVE_GCC_ATTRIBUTE_WARN_UNUSED 0
/* Guaranteed copy elision (C++17), __cpp_guaranteed_copy_elision (C++2a): */
#define HAVE_CPP_GUARANTEED_COPY_ELISION 0
#endif
......@@ -6482,6 +6482,29 @@ if test "$GCC" = yes; then
fi
AC_SUBST([HAVE_GCC_FNO_SIZED_DEALLOCATION])
HAVE_CPP_GUARANTEED_COPY_ELISION=
AC_MSG_CHECKING([whether $CXX supports guaranteed copy elision])
AC_LANG_PUSH([C++])
save_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#if !defined __cpp_guaranteed_copy_elision
struct S {
private:
S(S const &);
public:
S copy() const { return *this; }
};
void f(S & s) { S c(s.copy()); }
#endif
])], [
AC_DEFINE([HAVE_CPP_GUARANTEED_COPY_ELISION],[1])
AC_MSG_RESULT([yes])
], [AC_MSG_RESULT([no])])
CXXFLAGS=$save_CXXFLAGS
AC_LANG_POP([C++])
AC_SUBST([HAVE_CPP_GUARANTEED_COPY_ELISION])
dnl ===================================================================
dnl system stl sanity tests
dnl ===================================================================
......
......@@ -20,6 +20,9 @@
#ifndef INCLUDED_EDITENG_SWAFOPT_HXX
#define INCLUDED_EDITENG_SWAFOPT_HXX
#include <sal/config.h>
#include <config_global.h>
#include <editeng/editengdllapi.h>
#include <o3tl/sorted_vector.hxx>
#include <rtl/ustring.hxx>
......@@ -52,8 +55,23 @@ struct CompareAutoCompleteString
class SortedAutoCompleteStrings
: public o3tl::sorted_vector<IAutoCompleteString*, CompareAutoCompleteString>
{
bool owning_;
void operator =(SortedAutoCompleteStrings) = delete;
#if !HAVE_CPP_GUARANTEED_COPY_ELISION
public:
#endif
// For createNonOwningCopy only:
SortedAutoCompleteStrings(SortedAutoCompleteStrings const & other):
sorted_vector(other), owning_(false) {}
public:
~SortedAutoCompleteStrings() { DeleteAndDestroyAll(); }
SortedAutoCompleteStrings(): owning_(true) {}
~SortedAutoCompleteStrings() { if (owning_) DeleteAndDestroyAll(); }
SortedAutoCompleteStrings createNonOwningCopy() const { return *this; }
};
} // namespace editeng
......
......@@ -421,7 +421,7 @@ void SwDocShell::Execute(SfxRequest& rReq)
rACW.SetLockWordLstLocked( true );
editeng::SortedAutoCompleteStrings aTmpLst( rACW.GetWordList() );
editeng::SortedAutoCompleteStrings aTmpLst( rACW.GetWordList().createNonOwningCopy() );
pAFlags->m_pAutoCompleteList = &aTmpLst;
SfxApplication* pApp = SfxGetpApp();
......@@ -455,8 +455,6 @@ void SwDocShell::Execute(SfxRequest& rReq)
// clear the temp WordList pointer
pAFlags->m_pAutoCompleteList = nullptr;
}
// remove all pointer we never delete the strings
aTmpLst.clear();
if( !bOldAutoCmpltCollectWords && bOldAutoCmpltCollectWords !=
pAFlags->bAutoCmpltCollectWords )
......
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