diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-01-15 14:56:29 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-01-17 10:16:35 +0200 |
commit | 2e975301023354695e686812382b67c858774f67 (patch) | |
tree | 652b23baf265603cf3556e977b606c98d3041a9b /compilerplugins | |
parent | 48f89a858b13ac8d1bb7c1d2119126728e48d18a (diff) |
loplugin:useuniqueptr expand search for ranged-loop-delete
Change-Id: I78955f4db9b4da2858dfb25e69a5502eb0280418
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/test/useuniqueptr.cxx | 11 | ||||
-rw-r--r-- | compilerplugins/clang/useuniqueptr.cxx | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/compilerplugins/clang/test/useuniqueptr.cxx b/compilerplugins/clang/test/useuniqueptr.cxx index ddd30c73ae62..7495a9ec192d 100644 --- a/compilerplugins/clang/test/useuniqueptr.cxx +++ b/compilerplugins/clang/test/useuniqueptr.cxx @@ -8,6 +8,7 @@ */ #include <array> +#include <vector> #include <unordered_map> struct XXX { @@ -124,4 +125,14 @@ class Foo10 { } XXX* getOther() { return nullptr; } }; +class Foo11 { + std::vector<XXX*> m_pbar1; // expected-note {{member is here [loplugin:useuniqueptr]}} + ~Foo11() + { + for (const auto & p : m_pbar1) + { + delete p; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [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 c14d5fc5a57b..24992685df43 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -256,7 +256,11 @@ void UseUniquePtr::CheckForRangedLoopDelete(const CXXDestructorDecl* destructorD auto cxxForRangeStmt = dyn_cast<CXXForRangeStmt>(*i); if (!cxxForRangeStmt) continue; - auto deleteExpr = dyn_cast<CXXDeleteExpr>(cxxForRangeStmt->getBody()); + CXXDeleteExpr const * deleteExpr = nullptr; + if (auto compoundStmt = dyn_cast<CompoundStmt>(cxxForRangeStmt->getBody())) + deleteExpr = dyn_cast<CXXDeleteExpr>(*compoundStmt->body_begin()); + else + deleteExpr = dyn_cast<CXXDeleteExpr>(cxxForRangeStmt->getBody()); if (!deleteExpr) continue; auto memberExpr = dyn_cast<MemberExpr>(cxxForRangeStmt->getRangeInit()); |