Skip to content

Commit

Permalink
update useunique_ptr loplugin
Browse files Browse the repository at this point in the history
with more exclusions

Change-Id: I95e7376ecf9c479d05b85c71f863d9ba40417538
Reviewed-on: https://gerrit.libreoffice.org/66552
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
  • Loading branch information
Noel Grandin committed Jan 18, 2019
1 parent 0e4e586 commit 924da47
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 21 deletions.
12 changes: 6 additions & 6 deletions compilerplugins/clang/test/useuniqueptr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Class4 {
~Class4()
{
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 {
Expand Down Expand Up @@ -89,7 +89,7 @@ class Class7 {
~Class7()
{
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 {
Expand Down Expand Up @@ -162,7 +162,7 @@ class Foo12 {
{
int i = 0;
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 )
Expand Down Expand Up @@ -224,7 +224,7 @@ class Foo18 {
~Foo18()
{
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]}}
}
};

Expand Down Expand Up @@ -272,7 +272,7 @@ class Foo23
~Foo23()
{
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]}}
}
};

Expand All @@ -283,7 +283,7 @@ class Foo24
~Foo24()
{
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]}}
}
};

Expand Down
94 changes: 79 additions & 15 deletions compilerplugins/clang/useuniqueptr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
// ignore globals for now
Expand Down Expand Up @@ -464,6 +474,12 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
// linked list
if (fn == SRCDIR "/lotuswordpro/source/filter/lwpfribptr.cxx")
return;
// complicated
if (startswith(fn, SRCDIR "/connectivity/source/drivers/file/"))
return;
// complicated
if (startswith(fn, SRCDIR "/unodevtools/source/skeletonmaker/"))
return;

llvm::StringRef parentName;
if (auto cxxMethodDecl = dyn_cast<CXXMethodDecl>(functionDecl))
Expand All @@ -474,6 +490,9 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
// no idea what is going on here
if (parentName == "ScChangeActionLinkEntry")
return;
// ok
if (parentName == "SfxItemSet" || parentName == "SfxItemPool")
return;
// linked list
if (parentName == "ScFunctionList" || parentName == "SwNodes"
|| parentName == "SwUnoCursor" || parentName == "SortedResultSet"
Expand All @@ -485,8 +504,11 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
if (parentName == "ScBroadcastAreaSlot")
return;
// complicated
if (parentName == "SwFormatField" || parentName == "FontPropertyBox" || parentName == "SdFontPropertyBox"
|| parentName == "SwHTMLParser" || parentName == "PDFWriterImpl")
if (any_equal(parentName, "SwFormatField", "FontPropertyBox", "SdFontPropertyBox",
"SwHTMLParser", "PDFWriterImpl", "SbiParser", "DictionaryList", "SwGlossaryHdl", "SwGlossaryGroupDlg"))
return;
// ok
if (any_equal(parentName, "SbTreeListBox"))
return;

if (functionDecl->getIdentifier())
Expand All @@ -505,23 +527,61 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
|| name == "reg_openRegistry")
return;
// linked list
if (name == "TypeWriter::createBlop" || name == "ImplDeleteConfigData" || name == "Config::DeleteGroup"
|| name == "Config::DeleteKey")
if (any_equal(name, "TypeWriter::createBlop", "ImplDeleteConfigData", "Config::DeleteGroup",
"Config::DeleteKey", "E3dView::DoDepthArrange",
"DXFBlocks::Clear", "DXFTables::Clear", "DXFEntities::Clear",
"PSWriter::WritePS", "PSWriter::ImplWriteActions", "CUtList::Destroy",
"ScBroadcastAreaSlotMachine::UpdateBroadcastAreas"))
return;
// ok
if (name == "write_uInt16s_FromOUString" || name == "ProgressMonitor::removeText"
|| name == "StgDirEntry::SetSize" || name == "UCBStorage::CopyStorageElement_Impl"
|| parentName == "SfxItemSet" || parentName == "SfxItemPool"
|| name == "OutputDevice::ImplDrawPolyPolygon" || name == "OutputDevice::ImplDrawPolyPolygon"
|| name == "ImplListBox::InsertEntry" || name == "Edit::dispose")
if (any_equal(name, "write_uInt16s_FromOUString", "ProgressMonitor::removeText",
"StgDirEntry::SetSize", "UCBStorage::CopyStorageElement_Impl"
"OutputDevice::ImplDrawPolyPolygon", "OutputDevice::ImplDrawPolyPolygon",
"ImplListBox::InsertEntry", "Edit::dispose",
"ViewContact::deleteAllVOCs", "SfxViewFrame::ReleaseObjectShell_Impl",
"SfxViewFrame::SwitchToViewShell_Impl", "OfaSmartTagOptionsTabPage::ClearListBox",
"OfaSmartTagOptionsTabPage::FillItemSet", "doc_destroy", "lo_destroy",
"callColumnFormatDialog"))
return;
// very dodgy
if (name == "UCBStorage::OpenStorage_Impl")
if (any_equal(name, "UCBStorage::OpenStorage_Impl", "SdTransferable::GetData"))
return;
// complicated ownership
if (name == "ParseCMAP" || name == "OpenGLSalBitmap::CreateTexture" || name == "X11SalGraphicsImpl::drawAlphaBitmap"
|| name == "SvEmbedTransferHelper::GetData" || name == "ORoadmap::dispose"
|| name == "BrowseBox::SetMode" || name == "ExportDialog::GetFilterData")
if (any_equal(name, "ParseCMAP", "OpenGLSalBitmap::CreateTexture", "X11SalGraphicsImpl::drawAlphaBitmap"
"SvEmbedTransferHelper::GetData", "ORoadmap::dispose",
"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;
// complicated delete
if (name == "X11SalObject::CreateObject")
Expand Down Expand Up @@ -661,7 +721,7 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe
if (fn == SRCDIR "/sw/source/core/bastyp/swcache.cxx")
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)
Expand Down Expand Up @@ -759,7 +819,6 @@ void UseUniquePtr::CheckLoopDelete(const FunctionDecl* functionDecl, const CXXDe
if (fn == SRCDIR "/sw/qa/core/Test-BigPtrArray.cxx")
return;


report(
DiagnosticsEngine::Warning,
"loopdelete: rather manage this var with std::some_container<std::unique_ptr<T>>",
Expand Down Expand Up @@ -842,6 +901,11 @@ void UseUniquePtr::CheckCXXForRangeStmt(const FunctionDecl* functionDecl, const
// SfxPoolItem array
if (fn == SRCDIR "/reportdesign/source/ui/report/ReportController.cxx")
return;
// complicated
if (fn == SRCDIR "/svx/source/sdr/contact/viewcontact.cxx")
return;
if (fn == SRCDIR "/svx/source/sdr/contact/objectcontact.cxx")
return;

report(
DiagnosticsEngine::Warning,
Expand Down

0 comments on commit 924da47

Please sign in to comment.