compilerplugins/clang/scopedvclptr.cxx | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-)
New commits: commit d47b51a766564f3e5d1939a21a7e1ac4375d5cf1 Author: Stephan Bergmann <[email protected]> AuthorDate: Thu Mar 5 07:13:30 2026 +0100 Commit: Andras Timar <[email protected]> CommitDate: Tue Mar 10 00:27:40 2026 +0100 Some loplugin:scopedvclptr improvements * Make it part of the shared plugin, for performance (which requires the class to be named exactly "ScopedVclPtr", for the compilerplugins/clang/sharedvisitor/ machinery to work). * The main file name (which is always a .cxx file) can never be the /include/vcl/vclptr.hxx include file. * But we can restrict this plugin to C++; no sense in having it run on C code. * The [loplugin:...] marker is already printed automatically by the plugin, don't repeat it. Change-Id: I9725f27c0552cabec8fae13776796aad1ab1546d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201248 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 b9734a6332c3..dea3b0616bc5 100644 --- a/compilerplugins/clang/scopedvclptr.cxx +++ b/compilerplugins/clang/scopedvclptr.cxx @@ -7,12 +7,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef LO_CLANG_SHARED_PLUGINS + #include <cassert> #include <string> #include "check.hxx" #include "plugin.hxx" -#include "config_clang.h" /** * Two checks to prevent GDI handle leaks on Windows: @@ -146,21 +147,15 @@ static bool containsVclPtrCreate(const Stmt* pStmt) // plugin // --------------------------------------------------------------------------- -class ScopedVclPtrCheck : public loplugin::FilteringPlugin<ScopedVclPtrCheck> +class ScopedVclPtr : public loplugin::FilteringPlugin<ScopedVclPtr> { public: - explicit ScopedVclPtrCheck(loplugin::InstantiationData const& data) + explicit ScopedVclPtr(loplugin::InstantiationData const& data) : FilteringPlugin(data) { } - virtual bool preRun() override - { - StringRef fn(handler.getMainFileName()); - if (loplugin::isSamePathname(fn, SRCDIR "/include/vcl/vclptr.hxx")) - return false; - return true; - } + virtual bool preRun() override { return compiler.getLangOpts().CPlusPlus; } virtual void run() override { @@ -175,7 +170,7 @@ private: bool isVclPtrToVirtualDevice(QualType qType); }; -bool ScopedVclPtrCheck::isVclPtrToVirtualDevice(QualType qType) +bool ScopedVclPtr::isVclPtrToVirtualDevice(QualType qType) { auto check = loplugin::TypeCheck(qType); if (!check.TemplateSpecializationClass().Class("VclPtr").GlobalNamespace()) @@ -207,7 +202,7 @@ bool ScopedVclPtrCheck::isVclPtrToVirtualDevice(QualType qType) return bool(loplugin::TypeCheck(rArg.getAsType()).Class("VirtualDevice").GlobalNamespace()); } -bool ScopedVclPtrCheck::VisitVarDecl(const VarDecl* pVarDecl) +bool ScopedVclPtr::VisitVarDecl(const VarDecl* pVarDecl) { if (ignoreLocation(pVarDecl)) return true; @@ -248,15 +243,14 @@ bool ScopedVclPtrCheck::VisitVarDecl(const VarDecl* pVarDecl) report(DiagnosticsEngine::Warning, "use ScopedVclPtr<VirtualDevice> instead of VclPtr<VirtualDevice>" - " for local variables to prevent GDI handle leaks" - " [loplugin:scopedvclptr]", + " for local variables to prevent GDI handle leaks", pVarDecl->getLocation()) << pVarDecl->getSourceRange(); return true; } -bool ScopedVclPtrCheck::VisitFunctionDecl(const FunctionDecl* pFuncDecl) +bool ScopedVclPtr::VisitFunctionDecl(const FunctionDecl* pFuncDecl) { if (ignoreLocation(pFuncDecl)) return true; @@ -272,16 +266,17 @@ bool ScopedVclPtrCheck::VisitFunctionDecl(const FunctionDecl* pFuncDecl) report(DiagnosticsEngine::Warning, "use ScopedVclPtr<VirtualDevice> as return type instead of" - " VclPtr<VirtualDevice> to prevent GDI handle leaks" - " [loplugin:scopedvclptr]", + " VclPtr<VirtualDevice> to prevent GDI handle leaks", pFuncDecl->getLocation()) << pFuncDecl->getSourceRange(); return true; } -loplugin::Plugin::Registration<ScopedVclPtrCheck> scopedvclptr("scopedvclptr"); +loplugin::Plugin::Registration<ScopedVclPtr> scopedvclptr("scopedvclptr"); } // namespace +#endif + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
