From 8e39ef66928a3e37c618d3a70a631e71266db274 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 13 Jul 2017 20:42:04 +0200 Subject: extend loplugin useuniqueptr to POD types Change-Id: I6ff24f048bd8f75bf87a78b718f37b57855d4781 Reviewed-on: https://gerrit.libreoffice.org/39932 Tested-by: Jenkins Reviewed-by: Noel Grandin --- compilerplugins/clang/test/useuniqueptr.cxx | 9 ++++++--- compilerplugins/clang/useuniqueptr.cxx | 12 ++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/test/useuniqueptr.cxx b/compilerplugins/clang/test/useuniqueptr.cxx index e834123264e0..7e64bcca8986 100644 --- a/compilerplugins/clang/test/useuniqueptr.cxx +++ b/compilerplugins/clang/test/useuniqueptr.cxx @@ -7,9 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +struct XXX { + ~XXX() {} +}; class Foo1 { - char* m_pbar; // expected-note {{member is here [loplugin:useuniqueptr]}} + XXX* m_pbar; // expected-note {{member is here [loplugin:useuniqueptr]}} ~Foo1() { delete m_pbar; // expected-error {{a destructor with only a single unconditional call to delete on a member, is a sure sign it should be using std::unique_ptr for that field [loplugin:useuniqueptr]}} @@ -23,8 +26,8 @@ class Foo2 { char* m_pbar2; // expected-note {{member is here [loplugin:useuniqueptr]}} ~Foo2() { - delete[] m_pbar1; // expected-error {{managing array of trival type 'char' manually, rather use std::vector / std::array / std::unique_ptr [loplugin:useuniqueptr]}} - delete[] m_pbar2; // expected-error {{managing array of trival type 'char' manually, rather use std::vector / std::array / std::unique_ptr [loplugin:useuniqueptr]}} + delete[] m_pbar1; // expected-error {{managing POD type 'char' manually, rather use std::vector / std::array / std::unique_ptr [loplugin:useuniqueptr]}} + delete[] m_pbar2; // expected-error {{managing POD type 'char' manually, rather use std::vector / std::array / std::unique_ptr [loplugin:useuniqueptr]}} } }; diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index 9e0dd33e900b..dc1371f00b4a 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -37,7 +37,7 @@ public: bool VisitCompoundStmt(const CompoundStmt* ); private: void CheckForSingleUnconditionalDelete(const CXXDestructorDecl*, const CompoundStmt* ); - void CheckForDeleteArrayOfPOD(const CompoundStmt* ); + void CheckForDeleteOfPOD(const CompoundStmt* ); }; bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDecl) @@ -52,7 +52,7 @@ bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDec return true; CheckForSingleUnconditionalDelete(destructorDecl, compoundStmt); - CheckForDeleteArrayOfPOD(compoundStmt); + CheckForDeleteOfPOD(compoundStmt); return true; } @@ -195,13 +195,13 @@ bool UseUniquePtr::VisitCompoundStmt(const CompoundStmt* compoundStmt) return true; } -void UseUniquePtr::CheckForDeleteArrayOfPOD(const CompoundStmt* compoundStmt) +void UseUniquePtr::CheckForDeleteOfPOD(const CompoundStmt* compoundStmt) { for (auto i = compoundStmt->body_begin(); i != compoundStmt->body_end(); ++i) { auto deleteExpr = dyn_cast(*i); - if (!deleteExpr || !deleteExpr->isArrayForm()) + if (!deleteExpr) continue; const Expr* argExpr = deleteExpr->getArgument(); @@ -221,7 +221,7 @@ void UseUniquePtr::CheckForDeleteArrayOfPOD(const CompoundStmt* compoundStmt) auto pointerType = dyn_cast(fieldDecl->getType()->getUnqualifiedDesugaredType()); QualType elementType = pointerType->getPointeeType(); - if (!elementType.isTrivialType(compiler.getASTContext())) + if (!elementType.isPODType(compiler.getASTContext())) continue; StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart())); @@ -237,7 +237,7 @@ void UseUniquePtr::CheckForDeleteArrayOfPOD(const CompoundStmt* compoundStmt) report( DiagnosticsEngine::Warning, - "managing array of trival type %0 manually, rather use std::vector / std::array / std::unique_ptr", + "managing POD type %0 manually, rather use std::vector / std::array / std::unique_ptr", deleteExpr->getLocStart()) << elementType << deleteExpr->getSourceRange(); -- cgit v1.2.3