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.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;
}