compilerplugins/clang/scopedvclptr.cxx | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
New commits: commit 291c90af69efda181485a4c7b230d3bd6e227a91 Author: Stephan Bergmann <[email protected]> AuthorDate: Thu Mar 5 09:24:17 2026 +0100 Commit: Andras Timar <[email protected]> CommitDate: Mon Mar 9 09:55:02 2026 +0100 Streamline template specialization check in loplugin:scopedvclptr Maybe this sheds some light on why some Jenkins builds (like <https://cpci.cbg.collabora.co.uk:8080/job/gerrit_linux_co-26.04_clang_dbgutil/720/>) warn about > /home/collabora/jenkins/workspace/gerrit_linux_co-26.04_clang_dbgutil/sc/source/ui/sidebar/CellLineStyleControl.cxx:80:43: error: use ScopedVclPtr<VirtualDevice> as return type instead of VclPtr<VirtualDevice> to prevent GDI handle leaks [loplugin:scopedvclptr] [loplugin:scopedvclptr] > 80 | VclPtr<VirtualDevice> CellLineStylePopup::CreateImage(int nIndex) > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ > 81 | { > | ~ > 82 | VclPtr<VirtualDevice> pDev = mxCellLineStyleTreeView->create_virtual_device(); > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 83 | const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 84 | pDev->SetBackground(rStyleSettings.GetFieldColor()); > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 85 | pDev->SetLineColor(rStyleSettings.GetFieldTextColor()); > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 86 | pDev->SetFillColor(pDev->GetLineColor());; > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 87 | pDev->SetOutputSizePixel(Size(50, 26)); > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 88 | > 89 | constexpr tools::Long nX = 5; > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 90 | constexpr tools::Long nY = 10; > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 91 | constexpr tools::Long nTRX = 40; > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 92 | switch(nIndex) > | ~~~~~~~~~~~~~~ > 93 | { > | ~ > 94 | case 0: > | ~~~~~~~ > 95 | case 1: > | ~~~~~~~ as expected, while many other such Jenkins builds apparently don't Change-Id: Idc4561284b90f0f36acc148fd48b36f593b84754 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201006 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Andras Timar <[email protected]> diff --git a/compilerplugins/clang/scopedvclptr.cxx b/compilerplugins/clang/scopedvclptr.cxx index 9689a8cfec14..b9734a6332c3 100644 --- a/compilerplugins/clang/scopedvclptr.cxx +++ b/compilerplugins/clang/scopedvclptr.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <cassert> #include <string> #include "check.hxx" @@ -177,27 +178,31 @@ private: bool ScopedVclPtrCheck::isVclPtrToVirtualDevice(QualType qType) { auto check = loplugin::TypeCheck(qType); - if (!check.Class("VclPtr").GlobalNamespace()) + if (!check.TemplateSpecializationClass().Class("VclPtr").GlobalNamespace()) return false; - const clang::Type* pType = qType.getTypePtr(); - if (!pType) - return false; - - const CXXRecordDecl* pRecordDecl = pType->getAsCXXRecordDecl(); - if (!pRecordDecl) - return false; + const auto* pTemplate = qType->getAs<TemplateSpecializationType>(); + assert(pTemplate != nullptr); - const auto* pTemplate = dyn_cast<ClassTemplateSpecializationDecl>(pRecordDecl); - if (!pTemplate) - return false; - - if (pTemplate->getTemplateArgs().size() < 1) + auto const args = pTemplate->template_arguments(); + if (args.size() < 1) + { + if (isDebugMode()) + { + report(DiagnosticsEngine::Fatal, "Unexpected VclPtr specialization"); + } return false; + } - const TemplateArgument& rArg = pTemplate->getTemplateArgs()[0]; + const TemplateArgument& rArg = args[0]; if (rArg.getKind() != TemplateArgument::ArgKind::Type) + { + if (isDebugMode()) + { + report(DiagnosticsEngine::Fatal, "Unexpected VclPtr specialization"); + } return false; + } return bool(loplugin::TypeCheck(rArg.getAsType()).Class("VirtualDevice").GlobalNamespace()); }
