summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/redundantpointerops.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-10-07 15:45:13 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-10-08 08:26:23 +0200
commit231e16d9091c2d318d99c2f2eb985311e7138127 (patch)
tree7b8d30778cdb696cdf4c0ec80a58f6b488e4d5e5 /compilerplugins/clang/redundantpointerops.cxx
parente47172ce2ac486b909ee8f46380dca8efedb6a24 (diff)
loplugin:redundantpointerops simplify *p.get()
Change-Id: I12517651fb3f777fd08e384992bb3e84b340ad85 Reviewed-on: https://gerrit.libreoffice.org/80382 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/redundantpointerops.cxx')
-rw-r--r--compilerplugins/clang/redundantpointerops.cxx24
1 files changed, 17 insertions, 7 deletions
diff --git a/compilerplugins/clang/redundantpointerops.cxx b/compilerplugins/clang/redundantpointerops.cxx
index 68db603baf11..7c82825bd01d 100644
--- a/compilerplugins/clang/redundantpointerops.cxx
+++ b/compilerplugins/clang/redundantpointerops.cxx
@@ -113,14 +113,24 @@ bool RedundantPointerOps::VisitUnaryOperator(UnaryOperator const * unaryOperator
return true;
if (unaryOperator->getOpcode() != UO_Deref)
return true;
- auto innerOp = dyn_cast<UnaryOperator>(unaryOperator->getSubExpr()->IgnoreParenImpCasts());
- if (!innerOp || innerOp->getOpcode() != UO_AddrOf)
- return true;
+ auto subExpr = unaryOperator->getSubExpr()->IgnoreParenImpCasts();
+ auto innerOp = dyn_cast<UnaryOperator>(subExpr);
+ if (innerOp && innerOp->getOpcode() == UO_AddrOf)
+ report(
+ DiagnosticsEngine::Warning, "'&' followed by '*', rather use '.'",
+ compat::getBeginLoc(unaryOperator))
+ << unaryOperator->getSourceRange();
+ if (auto cxxMemberCallExpr = dyn_cast<CXXMemberCallExpr>(subExpr))
+ {
+ auto methodDecl = cxxMemberCallExpr->getMethodDecl();
+ if (methodDecl->getIdentifier() && methodDecl->getName() == "get"
+ && cxxMemberCallExpr->getRecordDecl()->getName() == "unique_ptr")
+ report(
+ DiagnosticsEngine::Warning, "'*' followed by '.get()', just use '*'",
+ compat::getBeginLoc(unaryOperator))
+ << unaryOperator->getSourceRange();
- report(
- DiagnosticsEngine::Warning, "'&' followed by '*', rather use '.'",
- compat::getBeginLoc(unaryOperator))
- << unaryOperator->getSourceRange();
+ }
return true;
}