new loplugin:simplifypointertobool
Change-Id: Iff68e8f379614a6ab6a6e0d1bad18e70bc76d76a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91907 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "compat.hxx"
|
||||
#include "pluginhandler.hxx"
|
||||
#include "check.hxx"
|
||||
|
||||
#if CLANG_VERSION >= 110000
|
||||
#include "clang/AST/ParentMapContext.h"
|
||||
@@ -801,6 +802,43 @@ bool hasExternalLinkage(VarDecl const * decl) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isSmartPointerType(const Expr* e)
|
||||
{
|
||||
// First check the object type as written, in case the get member function is
|
||||
// declared at a base class of std::unique_ptr or std::shared_ptr:
|
||||
auto const t = e->IgnoreImpCasts()->getType();
|
||||
auto const tc1 = loplugin::TypeCheck(t);
|
||||
if (tc1.ClassOrStruct("unique_ptr").StdNamespace()
|
||||
|| tc1.ClassOrStruct("shared_ptr").StdNamespace())
|
||||
return true;
|
||||
return isSmartPointerType(e->getType().getTypePtr());
|
||||
}
|
||||
|
||||
bool isSmartPointerType(const clang::Type* t)
|
||||
{
|
||||
// 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; but note that this will fail when the type-as-
|
||||
// written is derived from std::unique_ptr or std::shared_ptr for which the get
|
||||
// member function is declared at a base class):
|
||||
auto const tc2 = loplugin::TypeCheck(t);
|
||||
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())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
Reference in New Issue
Block a user