diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-12-17 14:38:44 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-12-17 15:02:00 +0100 |
commit | a214369f14d3f53d45b1889827057882c0ffd62e (patch) | |
tree | a9b0cccb45d25324dfa9225d5594607c988922f4 /compilerplugins/clang/plugin.cxx | |
parent | 6b2da3ae3ea7f47dff3c807c151f88a9e1ae9964 (diff) |
loplugin:unusedvariablecheck improve
to find unused smart pointer variables
Change-Id: I200bdd8949032a0e061de61f7903a156651793e2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127006
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/plugin.cxx')
-rw-r--r-- | compilerplugins/clang/plugin.cxx | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index 552f676735d3..57fdf83b79ff 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -818,6 +818,42 @@ bool hasExternalLinkage(VarDecl const * decl) { return true; } +bool isSmartPointerType(QualType qt) +{ + // First check whether the object type as written is, or is derived from, std::unique_ptr or + // std::shared_ptr, in case the get member function is declared at a base class of that std + // type: + if (loplugin::isDerivedFrom( + qt->getAsCXXRecordDecl(), + [](Decl const * decl) { + auto const dc = loplugin::DeclCheck(decl); + return dc.ClassOrStruct("unique_ptr").StdNamespace() + || dc.ClassOrStruct("shared_ptr").StdNamespace(); + })) + return true; + + // Then check the object type coerced to the type of the get member function, in + // case the type-as-written is derived from one of these types (tools::SvRef is + // final, but the rest are not): + auto const tc2 = loplugin::TypeCheck(qt); + if (tc2.ClassOrStruct("unique_ptr").StdNamespace() + || tc2.ClassOrStruct("shared_ptr").StdNamespace() + || tc2.Class("Reference").Namespace("uno").Namespace("star") + .Namespace("sun").Namespace("com").GlobalNamespace() + || tc2.Class("Reference").Namespace("rtl").GlobalNamespace() + || tc2.Class("SvRef").Namespace("tools").GlobalNamespace() + || tc2.Class("WeakReference").Namespace("tools").GlobalNamespace() + || tc2.Class("ScopedReadAccess").Namespace("Bitmap").GlobalNamespace() + || tc2.Class("ScopedVclPtrInstance").GlobalNamespace() + || tc2.Class("VclPtr").GlobalNamespace() + || tc2.Class("ScopedVclPtr").GlobalNamespace() + || tc2.Class("intrusive_ptr").Namespace("boost").GlobalNamespace()) + { + return true; + } + return false; +} + bool isSmartPointerType(const Expr* e) { // First check whether the object type as written is, or is derived from, std::unique_ptr or |