Kaydet (Commit) 924da47e authored tarafından Noel Grandin's avatar Noel Grandin

update useunique_ptr loplugin

with more exclusions

Change-Id: I95e7376ecf9c479d05b85c71f863d9ba40417538
Reviewed-on: https://gerrit.libreoffice.org/66552
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 0e4e5863
...@@ -53,7 +53,7 @@ class Class4 { ...@@ -53,7 +53,7 @@ class Class4 {
~Class4() ~Class4()
{ {
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
delete m_pbar[i]; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}} delete m_pbar[i]; // expected-error {{rather manage this member with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
} }
}; };
class Class5 { class Class5 {
...@@ -89,7 +89,7 @@ class Class7 { ...@@ -89,7 +89,7 @@ class Class7 {
~Class7() ~Class7()
{ {
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
delete m_pbar[i]; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}} delete m_pbar[i]; // expected-error {{rather manage this member with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
} }
}; };
class Class8 { class Class8 {
...@@ -162,7 +162,7 @@ class Foo12 { ...@@ -162,7 +162,7 @@ class Foo12 {
{ {
int i = 0; int i = 0;
while (i < 10) while (i < 10)
delete m_pbar[i++]; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}} delete m_pbar[i++]; // expected-error {{rather manage this member with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
} }
}; };
#define DELETEZ( p ) ( delete p,p = NULL ) #define DELETEZ( p ) ( delete p,p = NULL )
...@@ -224,7 +224,7 @@ class Foo18 { ...@@ -224,7 +224,7 @@ class Foo18 {
~Foo18() ~Foo18()
{ {
for (auto aIter = m_pbar1.begin(); aIter != m_pbar1.end(); ++aIter) for (auto aIter = m_pbar1.begin(); aIter != m_pbar1.end(); ++aIter)
delete *aIter; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}} delete *aIter; // expected-error {{rather manage this member with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
} }
}; };
...@@ -272,7 +272,7 @@ class Foo23 ...@@ -272,7 +272,7 @@ class Foo23
~Foo23() ~Foo23()
{ {
for(auto it = map.begin(); it != map.end(); ++it) for(auto it = map.begin(); it != map.end(); ++it)
delete it->second; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}} delete it->second; // expected-error {{rather manage this member with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
} }
}; };
...@@ -283,7 +283,7 @@ class Foo24 ...@@ -283,7 +283,7 @@ class Foo24
~Foo24() ~Foo24()
{ {
for ( HTMLAttrs::const_iterator it = m_aSetAttrTab.begin(); it != m_aSetAttrTab.end(); ++it ) for ( HTMLAttrs::const_iterator it = m_aSetAttrTab.begin(); it != m_aSetAttrTab.end(); ++it )
delete *it; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}} delete *it; // expected-error {{rather manage this member with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
} }
}; };
......
...@@ -299,6 +299,16 @@ void UseUniquePtr::CheckDeleteExpr(const FunctionDecl* functionDecl, const CXXDe ...@@ -299,6 +299,16 @@ void UseUniquePtr::CheckDeleteExpr(const FunctionDecl* functionDecl, const CXXDe
} }
} }
template<typename T>
bool any_equal(std::string const & needle, T first) {
return needle == first;
}
template<typename T, typename... Args>
bool any_equal(std::string const & needle, T first, Args... args) {
return needle == first || any_equal(needle, args...);
}
void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const CXXDeleteExpr* deleteExpr, const VarDecl* varDecl) void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const CXXDeleteExpr* deleteExpr, const VarDecl* varDecl)
{ {
// ignore globals for now // ignore globals for now
...@@ -464,6 +474,12 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C ...@@ -464,6 +474,12 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
// linked list // linked list
if (fn == SRCDIR "/lotuswordpro/source/filter/lwpfribptr.cxx") if (fn == SRCDIR "/lotuswordpro/source/filter/lwpfribptr.cxx")
return; return;
// complicated
if (startswith(fn, SRCDIR "/connectivity/source/drivers/file/"))
return;
// complicated
if (startswith(fn, SRCDIR "/unodevtools/source/skeletonmaker/"))
return;
llvm::StringRef parentName; llvm::StringRef parentName;
if (auto cxxMethodDecl = dyn_cast<CXXMethodDecl>(functionDecl)) if (auto cxxMethodDecl = dyn_cast<CXXMethodDecl>(functionDecl))
...@@ -474,6 +490,9 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C ...@@ -474,6 +490,9 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
// no idea what is going on here // no idea what is going on here
if (parentName == "ScChangeActionLinkEntry") if (parentName == "ScChangeActionLinkEntry")
return; return;
// ok
if (parentName == "SfxItemSet" || parentName == "SfxItemPool")
return;
// linked list // linked list
if (parentName == "ScFunctionList" || parentName == "SwNodes" if (parentName == "ScFunctionList" || parentName == "SwNodes"
|| parentName == "SwUnoCursor" || parentName == "SortedResultSet" || parentName == "SwUnoCursor" || parentName == "SortedResultSet"
...@@ -485,8 +504,11 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C ...@@ -485,8 +504,11 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
if (parentName == "ScBroadcastAreaSlot") if (parentName == "ScBroadcastAreaSlot")
return; return;
// complicated // complicated
if (parentName == "SwFormatField" || parentName == "FontPropertyBox" || parentName == "SdFontPropertyBox" if (any_equal(parentName, "SwFormatField", "FontPropertyBox", "SdFontPropertyBox",
|| parentName == "SwHTMLParser" || parentName == "PDFWriterImpl") "SwHTMLParser", "PDFWriterImpl", "SbiParser", "DictionaryList", "SwGlossaryHdl", "SwGlossaryGroupDlg"))
return;
// ok
if (any_equal(parentName, "SbTreeListBox"))
return; return;
if (functionDecl->getIdentifier()) if (functionDecl->getIdentifier())
...@@ -505,23 +527,61 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C ...@@ -505,23 +527,61 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
|| name == "reg_openRegistry") || name == "reg_openRegistry")
return; return;
// linked list // linked list
if (name == "TypeWriter::createBlop" || name == "ImplDeleteConfigData" || name == "Config::DeleteGroup" if (any_equal(name, "TypeWriter::createBlop", "ImplDeleteConfigData", "Config::DeleteGroup",
|| name == "Config::DeleteKey") "Config::DeleteKey", "E3dView::DoDepthArrange",
"DXFBlocks::Clear", "DXFTables::Clear", "DXFEntities::Clear",
"PSWriter::WritePS", "PSWriter::ImplWriteActions", "CUtList::Destroy",
"ScBroadcastAreaSlotMachine::UpdateBroadcastAreas"))
return; return;
// ok // ok
if (name == "write_uInt16s_FromOUString" || name == "ProgressMonitor::removeText" if (any_equal(name, "write_uInt16s_FromOUString", "ProgressMonitor::removeText",
|| name == "StgDirEntry::SetSize" || name == "UCBStorage::CopyStorageElement_Impl" "StgDirEntry::SetSize", "UCBStorage::CopyStorageElement_Impl"
|| parentName == "SfxItemSet" || parentName == "SfxItemPool" "OutputDevice::ImplDrawPolyPolygon", "OutputDevice::ImplDrawPolyPolygon",
|| name == "OutputDevice::ImplDrawPolyPolygon" || name == "OutputDevice::ImplDrawPolyPolygon" "ImplListBox::InsertEntry", "Edit::dispose",
|| name == "ImplListBox::InsertEntry" || name == "Edit::dispose") "ViewContact::deleteAllVOCs", "SfxViewFrame::ReleaseObjectShell_Impl",
"SfxViewFrame::SwitchToViewShell_Impl", "OfaSmartTagOptionsTabPage::ClearListBox",
"OfaSmartTagOptionsTabPage::FillItemSet", "doc_destroy", "lo_destroy",
"callColumnFormatDialog"))
return; return;
// very dodgy // very dodgy
if (name == "UCBStorage::OpenStorage_Impl") if (any_equal(name, "UCBStorage::OpenStorage_Impl", "SdTransferable::GetData"))
return; return;
// complicated ownership // complicated ownership
if (name == "ParseCMAP" || name == "OpenGLSalBitmap::CreateTexture" || name == "X11SalGraphicsImpl::drawAlphaBitmap" if (any_equal(name, "ParseCMAP", "OpenGLSalBitmap::CreateTexture", "X11SalGraphicsImpl::drawAlphaBitmap"
|| name == "SvEmbedTransferHelper::GetData" || name == "ORoadmap::dispose" "SvEmbedTransferHelper::GetData", "ORoadmap::dispose",
|| name == "BrowseBox::SetMode" || name == "ExportDialog::GetFilterData") "BrowseBox::SetMode", "ExportDialog::GetFilterData", "disposeComVariablesForBasic",
"ImpEditEngine::ImpRemoveParagraph", "FactoryImpl::createAdapter",
"SfxStateCache::SetVisibleState", "SfxBindings::QueryState",
"ViewContact::deleteAllVOCs", "SvxMSDffManager::ProcessObj", "SvEmbedTransferHelper::GetData",
"SvXMLExportPropertyMapper::Filter_", "SdXMLExport::ImpGetOrCreatePageMasterInfo",
"SfxDocumentDescPage::FillItemSet", "SfxCustomPropertiesPage::FillItemSet",
"SfxCmisPropertiesPage::FillItemSet", "SfxObjectShell::DoSaveCompleted",
"SfxObjectShell::DoSave_Impl", "SfxObjectShell::PreDoSaveAs_Impl", "SfxObjectShell::Save_Impl",
"SfxFrame::DoClose_Impl", "SfxBaseModel::load",
"SdrTextObj::TakeTextRect", "SdrTableObj::TakeTextRect", "SdrObjCustomShape::TakeTextRect",
"CellProperties::ItemSetChanged", "CellProperties::ItemChange",
"TableLayouter::SetBorder", "TableLayouter::ClearBorderLayout",
"ImpXPolygon::Resize", "SvxTextEditSourceImpl::GetBackgroundTextForwarder",
"Svx3DSceneObject::setPropertyValueImpl", "lcl_RemoveTextEditOutlinerViews",
"SdrObjEditView::SdrEndTextEdit", "SvxShape::_setPropertyValue",
"AccessibleShape::Init", "AccessibleCell::Init",
"SdrTableRtfExporter::WriteCell", "GalleryItem::_getPropertyValues",
"VMLExport::StartShape", "DrawingML::WriteText",
"MtfTools::DrawText", "FormulaTokenArray::RewriteMissing",
"OSQLParseNode::negateSearchCondition", "OSQLParseNodesContainer::clearAndDelete",
"SdFilter::GetLibrarySymbol", "SdPage::SetObjText",
"SdDrawDocument::InsertBookmarkAsPage", "SdDrawDocument::InsertBookmarkAsObject",
"SdDrawDocument::RemoveUnnecessaryMasterPages",
"ScTable::CopyConditionalFormat", "ScTable::ValidQuery",
"ScTable::SetOptimalHeight", "ScTable::SetOptimalHeightOnly", "ScCompiler::CompileString",
"ScProgress::DeleteInterpretProgress", "ScInterpreter::ScBase",
"UCBStorage::CopyStorageElement_Impl", "X11SalGraphicsImpl::drawAlphaBitmap",
"MasterPagesSelector::ClearPageSet", "View::IsPresObjSelected",
"SdDrawPagesAccess::remove", "SdMasterPagesAccess::remove", "View::InsertData",
"RemoteServer::execute", "Implementation::ReleaseOutlinerView",
"SwFormat::CopyAttrs", "FinitCore", "SwCursorShell::MoveFieldType", "SwExtraPainter::PaintExtra",
"SwMarginPortion::AdjustRight", "SwPaintQueue::Repaint", "SwTOXMgr::UpdateOrInsertTOX",
"SwBaseShell::Execute", "WW8Export::WriteSdrTextObj"))
return; return;
// complicated delete // complicated delete
if (name == "X11SalObject::CreateObject") if (name == "X11SalObject::CreateObject")
...@@ -661,7 +721,7 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe ...@@ -661,7 +721,7 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe
if (fn == SRCDIR "/sw/source/core/bastyp/swcache.cxx") if (fn == SRCDIR "/sw/source/core/bastyp/swcache.cxx")
return; return;
CheckMemberDeleteExpr(functionDecl, deleteExpr, memberExpr, "rather manage with std::some_container<std::unique_ptr<T>>"); CheckMemberDeleteExpr(functionDecl, deleteExpr, memberExpr, "rather manage this member with std::some_container<std::unique_ptr<T>>");
} }
if (varDecl) if (varDecl)
...@@ -759,7 +819,6 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe ...@@ -759,7 +819,6 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe
if (fn == SRCDIR "/sw/qa/core/Test-BigPtrArray.cxx") if (fn == SRCDIR "/sw/qa/core/Test-BigPtrArray.cxx")
return; return;
report( report(
DiagnosticsEngine::Warning, DiagnosticsEngine::Warning,
"loopdelete: rather manage this var with std::some_container<std::unique_ptr<T>>", "loopdelete: rather manage this var with std::some_container<std::unique_ptr<T>>",
...@@ -842,6 +901,11 @@ void UseUniquePtr::CheckCXXForRangeStmt(const FunctionDecl* functionDecl, const ...@@ -842,6 +901,11 @@ void UseUniquePtr::CheckCXXForRangeStmt(const FunctionDecl* functionDecl, const
// SfxPoolItem array // SfxPoolItem array
if (fn == SRCDIR "/reportdesign/source/ui/report/ReportController.cxx") if (fn == SRCDIR "/reportdesign/source/ui/report/ReportController.cxx")
return; return;
// complicated
if (fn == SRCDIR "/svx/source/sdr/contact/viewcontact.cxx")
return;
if (fn == SRCDIR "/svx/source/sdr/contact/objectcontact.cxx")
return;
report( report(
DiagnosticsEngine::Warning, DiagnosticsEngine::Warning,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment