diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-04-06 09:46:06 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-04-06 09:22:46 +0000 |
commit | aa09b0c27a6d925da428d6267daadc7338829869 (patch) | |
tree | b0fa576ff64820061d9fb876bebacd23e58ddc56 /compilerplugins | |
parent | 0c82dff153d92150729815b919854a9a350aa031 (diff) |
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 <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/useuniqueptr.cxx | 13 |
1 files changed, 9 insertions, 4 deletions
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<CXXDeleteExpr>(compoundStmt->body_back()); + auto lastStmt = compoundStmt->body_back(); + if (compoundStmt->size() > 1) { + if (isa<ReturnStmt>(lastStmt)) + lastStmt = *(++compoundStmt->body_rbegin()); + } + auto deleteExpr = dyn_cast<CXXDeleteExpr>(lastStmt); if (deleteExpr == nullptr) { return true; } - const ImplicitCastExpr* pCastExpr = dyn_cast<ImplicitCastExpr>(deleteExpr->getArgument()); + auto pCastExpr = dyn_cast<ImplicitCastExpr>(deleteExpr->getArgument()); if (!pCastExpr) return true; - const DeclRefExpr* declRefExpr = dyn_cast<DeclRefExpr>(pCastExpr->getSubExpr()); + auto declRefExpr = dyn_cast<DeclRefExpr>(pCastExpr->getSubExpr()); if (!declRefExpr) return true; - const VarDecl* varDecl = dyn_cast<VarDecl>(declRefExpr->getDecl()); + auto varDecl = dyn_cast<VarDecl>(declRefExpr->getDecl()); if (!varDecl) return true; if (!varDecl->hasInit() || !dyn_cast<CXXNewExpr>(varDecl->getInit())) |