summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-01-12 08:22:39 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-01-15 07:28:35 +0100
commit397d5cbc3c04da7693e2e1f3e99b0d8e431bfff2 (patch)
treed064789b3a170293ff0f57b7f2b1b1b79159b18b /compilerplugins
parenta2f86708a5740ce9fd2a3a6ab69685d8fb53dd6c (diff)
loplugin:useuniqueptr in Cursor
Change-Id: I5de300709409311b7a1d451ee1d314596cf2e879 Reviewed-on: https://gerrit.libreoffice.org/47836 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/test/useuniqueptr.cxx12
-rw-r--r--compilerplugins/clang/useuniqueptr.cxx5
2 files changed, 17 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/useuniqueptr.cxx b/compilerplugins/clang/test/useuniqueptr.cxx
index 43002ec59a68..ddd30c73ae62 100644
--- a/compilerplugins/clang/test/useuniqueptr.cxx
+++ b/compilerplugins/clang/test/useuniqueptr.cxx
@@ -112,4 +112,16 @@ class Foo9 {
delete m_pbar3; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
}
};
+// no warning expected
+class Foo10 {
+ XXX* m_pbar1;
+ ~Foo10()
+ {
+ if (m_pbar1 != getOther())
+ {
+ delete m_pbar1;
+ }
+ }
+ XXX* getOther() { return nullptr; }
+};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx
index 99ef6928533e..c14d5fc5a57b 100644
--- a/compilerplugins/clang/useuniqueptr.cxx
+++ b/compilerplugins/clang/useuniqueptr.cxx
@@ -88,6 +88,8 @@ void UseUniquePtr::CheckForUnconditionalDelete(const CXXDestructorDecl* destruct
{
if (!isa<MemberExpr>(binaryOp->getLHS()->IgnoreImpCasts()))
continue;
+ if (!isa<CXXNullPtrLiteralExpr>(binaryOp->getRHS()->IgnoreImpCasts()))
+ continue;
}
else
continue;
@@ -109,6 +111,9 @@ void UseUniquePtr::CheckForUnconditionalDelete(const CXXDestructorDecl* destruct
}
}
+/**
+ * Check the delete expression in a destructor.
+ */
void UseUniquePtr::CheckDeleteExpr(const CXXDestructorDecl* destructorDecl, const CXXDeleteExpr* deleteExpr)
{
const ImplicitCastExpr* pCastExpr = dyn_cast<ImplicitCastExpr>(deleteExpr->getArgument());