From eb3cee606e74b9ddfbfcb80a6664868aed44cd89 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 14 Apr 2026 10:33:40 +0200 Subject: [PATCH] template static field appearing in two different CUs I saw some warnings and got suspicious, so I converted the OSL_ENSURE to assert, and then found that we have two copies of the s_nRefCount static field, which obviously causes trouble. I tried to fix this by removing usage of this dubious template class, but the templates classes are intertwined, and that lead to a very large patch with weird failures. So this is a hacky minimal fix, using explicit template instantiation to force the code to only be emitted in a single library. Change-Id: I634afb8b40570f2e7e0f8da541b8a2b6325fdc29 Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/904 Reviewed-by: Noel Grandin Tested-by: Jenkins CPCI (cherry picked from commit af69817a343ccf1411f6f8980c94ed1f696769b4) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207023 Reviewed-by: Julien Nabet Tested-by: Jenkins --- include/comphelper/proparrhlp.hxx | 6 +++--- include/svtools/toolboxcontroller.hxx | 8 ++++++++ svtools/source/uno/toolboxcontroller.cxx | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/comphelper/proparrhlp.hxx b/include/comphelper/proparrhlp.hxx index 9093ff579f0c..b4e6ac6071fa 100644 --- a/include/comphelper/proparrhlp.hxx +++ b/include/comphelper/proparrhlp.hxx @@ -100,7 +100,7 @@ template OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper() { std::unique_lock aGuard(theMutex()); - OSL_ENSURE(s_nRefCount > 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !"); + assert(s_nRefCount > 0 && "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !"); if (!--s_nRefCount) { delete s_pProps; @@ -111,12 +111,12 @@ OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper() template ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper::getArrayHelper() { - OSL_ENSURE(s_nRefCount, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !"); std::unique_lock aGuard(theMutex()); + assert(s_nRefCount && "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !"); if (!s_pProps) { s_pProps = createArrayHelper(); - OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !"); + assert(s_pProps && "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !"); } return s_pProps; } diff --git a/include/svtools/toolboxcontroller.hxx b/include/svtools/toolboxcontroller.hxx index 526cadb3321b..5454406c6875 100644 --- a/include/svtools/toolboxcontroller.hxx +++ b/include/svtools/toolboxcontroller.hxx @@ -45,6 +45,14 @@ namespace weld { class Toolbar; } class ToolBox; +namespace svt +{ + class ToolboxController; +} + +// extern template otherwise the ref-counting magic here ends up duplicated across multiple libraries +extern template class SAL_DLLPUBLIC_TEMPLATE comphelper::OPropertyArrayUsageHelper; + namespace svt { diff --git a/svtools/source/uno/toolboxcontroller.cxx b/svtools/source/uno/toolboxcontroller.cxx index 4583e88d849e..bd6f61949f81 100644 --- a/svtools/source/uno/toolboxcontroller.cxx +++ b/svtools/source/uno/toolboxcontroller.cxx @@ -48,6 +48,8 @@ using namespace css::beans; using namespace css::lang; using namespace css::frame; +template class comphelper::OPropertyArrayUsageHelper; + namespace svt {