diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-07 15:45:13 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-08 08:26:23 +0200 |
commit | 231e16d9091c2d318d99c2f2eb985311e7138127 (patch) | |
tree | 7b8d30778cdb696cdf4c0ec80a58f6b488e4d5e5 /compilerplugins | |
parent | e47172ce2ac486b909ee8f46380dca8efedb6a24 (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')
-rw-r--r-- | compilerplugins/clang/redundantpointerops.cxx | 24 | ||||
-rw-r--r-- | compilerplugins/clang/test/redundantpointerops.cxx | 10 |
2 files changed, 27 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; } diff --git a/compilerplugins/clang/test/redundantpointerops.cxx b/compilerplugins/clang/test/redundantpointerops.cxx index c218c089caba..30c22b02614f 100644 --- a/compilerplugins/clang/test/redundantpointerops.cxx +++ b/compilerplugins/clang/test/redundantpointerops.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <memory> + struct Struct1 { int x; }; @@ -35,4 +37,12 @@ void function3(Struct1& s) //{ // (*s).x = 1; // xxexpected-error {{'*' followed by '.', rather use '->' [loplugin:redundantpointerops]}} //}; + +int function5(std::unique_ptr<int> x) +{ + return *x.get(); // expected-error {{'*' followed by '.get()', just use '*' [loplugin:redundantpointerops]}} +}; + + + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |