summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/redundantpointerops.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/redundantpointerops.cxx')
-rw-r--r--compilerplugins/clang/redundantpointerops.cxx39
1 files changed, 2 insertions, 37 deletions
diff --git a/compilerplugins/clang/redundantpointerops.cxx b/compilerplugins/clang/redundantpointerops.cxx
index 7012365aaef3..45b0783af0ab 100644
--- a/compilerplugins/clang/redundantpointerops.cxx
+++ b/compilerplugins/clang/redundantpointerops.cxx
@@ -53,8 +53,6 @@ public:
bool VisitFunctionDecl(FunctionDecl const *);
bool VisitMemberExpr(MemberExpr const *);
bool VisitUnaryOperator(UnaryOperator const *);
-private:
- bool isSmartPointerType(const Expr* e);
};
bool RedundantPointerOps::VisitFunctionDecl(FunctionDecl const * functionDecl)
@@ -104,7 +102,7 @@ bool RedundantPointerOps::VisitMemberExpr(MemberExpr const * memberExpr)
if (methodDecl->getIdentifier() && methodDecl->getName() == "get")
{
auto const e = cxxMemberCallExpr->getImplicitObjectArgument();
- if (isSmartPointerType(e))
+ if (loplugin::isSmartPointerType(e))
report(
DiagnosticsEngine::Warning,
"'get()' followed by '->' operating on %0, just use '->'",
@@ -150,7 +148,7 @@ bool RedundantPointerOps::VisitUnaryOperator(UnaryOperator const * unaryOperator
if (methodDecl->getIdentifier() && methodDecl->getName() == "get")
{
auto const e = cxxMemberCallExpr->getImplicitObjectArgument();
- if (isSmartPointerType(e))
+ if (loplugin::isSmartPointerType(e))
report(
DiagnosticsEngine::Warning,
"'*' followed by '.get()' operating on %0, just use '*'",
@@ -162,39 +160,6 @@ bool RedundantPointerOps::VisitUnaryOperator(UnaryOperator const * unaryOperator
return true;
}
-bool RedundantPointerOps::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;
-
- // 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(e->getType());
- 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;
-}
-
loplugin::Plugin::Registration< RedundantPointerOps > redundantpointerops("redundantpointerops");
} // namespace