summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-05-02 14:46:26 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-05-03 08:25:43 +0200
commitae680f7c7d45b7f6cff4dc458d5ad37c5f777948 (patch)
tree65d5ff5411080492f933a42080590dfaedd7793a /compilerplugins
parentee3898f9a167a9d876b49d38f57f2b455cf28b48 (diff)
make useuniqueptr loplugin check child compound statements
where the child compound statement is unconditional Change-Id: I755e7ee9134bde81811a694d42a996d3eaae3fc2 Reviewed-on: https://gerrit.libreoffice.org/53763 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.cxx10
-rw-r--r--compilerplugins/clang/useuniqueptr.cxx13
2 files changed, 21 insertions, 2 deletions
diff --git a/compilerplugins/clang/test/useuniqueptr.cxx b/compilerplugins/clang/test/useuniqueptr.cxx
index a68cea3201d0..8ef71175bb99 100644
--- a/compilerplugins/clang/test/useuniqueptr.cxx
+++ b/compilerplugins/clang/test/useuniqueptr.cxx
@@ -162,4 +162,14 @@ class Foo13 {
DELETEZ(m_pbar2); // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
}
};
+// check for unconditional inner compound statements
+class Foo14 {
+ int * m_pbar1; // expected-note {{member is here [loplugin:useuniqueptr]}}
+ ~Foo14()
+ {
+ {
+ delete m_pbar1; // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
+ }
+ }
+};
/* 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 0aab2a644bfb..ce09b5873cbb 100644
--- a/compilerplugins/clang/useuniqueptr.cxx
+++ b/compilerplugins/clang/useuniqueptr.cxx
@@ -52,6 +52,7 @@ public:
bool VisitCXXMethodDecl(const CXXMethodDecl* );
bool VisitCompoundStmt(const CompoundStmt* );
private:
+ void CheckCompoundStmt(const CXXMethodDecl*, const CompoundStmt* );
void CheckForUnconditionalDelete(const CXXMethodDecl*, const CompoundStmt* );
void CheckForSimpleDelete(const CXXMethodDecl*, const CompoundStmt* );
void CheckRangedLoopDelete(const CXXMethodDecl*, const CXXForRangeStmt* );
@@ -74,6 +75,13 @@ bool UseUniquePtr::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl)
if (!compoundStmt || compoundStmt->size() == 0)
return true;
+ CheckCompoundStmt(methodDecl, compoundStmt);
+
+ return true;
+}
+
+void UseUniquePtr::CheckCompoundStmt(const CXXMethodDecl* methodDecl, const CompoundStmt* compoundStmt)
+{
CheckForSimpleDelete(methodDecl, compoundStmt);
for (auto i = compoundStmt->body_begin(); i != compoundStmt->body_end(); ++i)
@@ -84,9 +92,10 @@ bool UseUniquePtr::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl)
CheckLoopDelete(methodDecl, forStmt->getBody());
else if (auto whileStmt = dyn_cast<WhileStmt>(*i))
CheckLoopDelete(methodDecl, whileStmt->getBody());
+ // check for unconditional inner compound statements
+ else if (auto innerCompoundStmt = dyn_cast<CompoundStmt>(*i))
+ CheckCompoundStmt(methodDecl, innerCompoundStmt);
}
-
- return true;
}
/**