diff options
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: */ |