[Libreoffice-commits] core.git: config_host/config_global.h.in configure.ac include/editeng sw/source
Stephan Bergmann
sbergman at redhat.com
Wed Jul 4 21:04:26 UTC 2018
config_host/config_global.h.in | 3 +++
configure.ac | 23 +++++++++++++++++++++++
include/editeng/swafopt.hxx | 20 +++++++++++++++++++-
sw/source/uibase/app/docsh2.cxx | 4 +---
4 files changed, 46 insertions(+), 4 deletions(-)
New commits:
commit a9303d85a4f201a42322e8e4ce5ebe6e6ca728b0
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Wed Jul 4 15:51:02 2018 +0200
Make brittle SortedAutoCompleteStrings ownership handling more explicit
Change-Id: Ieaf2231a84d97528bb1b9a410c4ee0c38966dd27
Reviewed-on: https://gerrit.libreoffice.org/56950
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/config_host/config_global.h.in b/config_host/config_global.h.in
index e0dc1418e9cb..2bb60ca656ac 100644
--- a/config_host/config_global.h.in
+++ b/config_host/config_global.h.in
@@ -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
diff --git a/configure.ac b/configure.ac
index bc76475962c9..45c19e72b9c0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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 ===================================================================
diff --git a/include/editeng/swafopt.hxx b/include/editeng/swafopt.hxx
index e8d7d3a6facf..f3b34adb32a7 100644
--- a/include/editeng/swafopt.hxx
+++ b/include/editeng/swafopt.hxx
@@ -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
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx
index 1d1972da0f04..ab4c22a5b718 100644
--- a/sw/source/uibase/app/docsh2.cxx
+++ b/sw/source/uibase/app/docsh2.cxx
@@ -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 )
More information about the Libreoffice-commits
mailing list