From aa09b0c27a6d925da428d6267daadc7338829869 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 6 Apr 2017 09:46:06 +0200 Subject: loplugin:useuniqueptr extend to catch more localvar cases i.e. where the code looks like { foo * p = new foo; ... delete p; return ...; } Change-Id: Id5f2e55d0363fc62c72535a23faeaaf1f0ac6aee Reviewed-on: https://gerrit.libreoffice.org/36190 Tested-by: Jenkins Reviewed-by: Noel Grandin --- compilerplugins/clang/useuniqueptr.cxx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'compilerplugins/clang') diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index 155fa0e2b568..a76f65d85afa 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -141,18 +141,23 @@ bool UseUniquePtr::VisitCompoundStmt(const CompoundStmt* compoundStmt) return true; } - const CXXDeleteExpr* deleteExpr = dyn_cast(compoundStmt->body_back()); + auto lastStmt = compoundStmt->body_back(); + if (compoundStmt->size() > 1) { + if (isa(lastStmt)) + lastStmt = *(++compoundStmt->body_rbegin()); + } + auto deleteExpr = dyn_cast(lastStmt); if (deleteExpr == nullptr) { return true; } - const ImplicitCastExpr* pCastExpr = dyn_cast(deleteExpr->getArgument()); + auto pCastExpr = dyn_cast(deleteExpr->getArgument()); if (!pCastExpr) return true; - const DeclRefExpr* declRefExpr = dyn_cast(pCastExpr->getSubExpr()); + auto declRefExpr = dyn_cast(pCastExpr->getSubExpr()); if (!declRefExpr) return true; - const VarDecl* varDecl = dyn_cast(declRefExpr->getDecl()); + auto varDecl = dyn_cast(declRefExpr->getDecl()); if (!varDecl) return true; if (!varDecl->hasInit() || !dyn_cast(varDecl->getInit())) -- cgit