Kaydet (Commit) 497e40ad authored tarafından Noel Grandin's avatar Noel Grandin

improve refcounting loplugin

to find ref-counted classes being managed via other smart pointer
classes.
Hopefully prevent needing fixes like
642ae256
"ChangedUIEventListener is refcounted, mustn't be helt by unique_ptr"

Change-Id: I6b0c5f8f87ce3546a8a1104ce1000470c09459bd
Reviewed-on: https://gerrit.libreoffice.org/39378Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 71112060
......@@ -386,28 +386,67 @@ bool RefCounting::VisitFieldDecl(const FieldDecl * fieldDecl) {
return true;
}
std::string aParentName = fieldDecl->getParent()->getQualifiedNameAsString();
// check for dodgy code managing ref-counted stuff with shared_ptr or unique_ptr or similar stuff
QualType firstTemplateParamType;
if (auto recordType = fieldDecl->getType()->getUnqualifiedDesugaredType()->getAs<RecordType>()) {
auto recordDeclName = recordType->getDecl()->getName();
if (recordDeclName.find("unique_ptr") != StringRef::npos
|| recordDeclName.find("shared_ptr") != StringRef::npos
|| recordDeclName.find("intrusive_ptr") != StringRef::npos) // boost
{
auto templateDecl = dyn_cast<ClassTemplateSpecializationDecl>(recordType->getDecl());
if (templateDecl && templateDecl->getTemplateArgs().size() > 0)
firstTemplateParamType = templateDecl->getTemplateArgs()[0].getAsType();
}
}
if (containsSvRefBaseSubclass(fieldDecl->getType().getTypePtr())) {
report(
DiagnosticsEngine::Warning,
"SvRefBase subclass being directly heap managed, should be managed via tools::SvRef, "
+ fieldDecl->getType().getAsString()
+ ", parent is " + aParentName,
"SvRefBase subclass %0 being directly heap managed, should be managed via tools::SvRef, "
", parent is %1",
fieldDecl->getLocation())
<< fieldDecl->getSourceRange();
<< fieldDecl->getType()
<< fieldDecl->getParent()
<< fieldDecl->getSourceRange();
}
if (!firstTemplateParamType.isNull() && containsSvRefBaseSubclass(firstTemplateParamType.getTypePtr()))
{
report(
DiagnosticsEngine::Warning,
"SvRefBase subclass %0 being managed via smart pointer, should be managed via tools::SvRef, "
"parent is %1",
fieldDecl->getLocation())
<< firstTemplateParamType
<< fieldDecl->getParent()
<< fieldDecl->getSourceRange();
}
if (containsSalhelperReferenceObjectSubclass(fieldDecl->getType().getTypePtr())) {
report(
DiagnosticsEngine::Warning,
"salhelper::SimpleReferenceObject subclass being directly heap managed, should be managed via rtl::Reference, "
+ fieldDecl->getType().getAsString()
+ ", parent is " + aParentName,
"salhelper::SimpleReferenceObject subclass %0 being directly heap managed, should be managed via rtl::Reference, "
"parent is %1",
fieldDecl->getLocation())
<< fieldDecl->getType()
<< fieldDecl->getParent()
<< fieldDecl->getSourceRange();
}
if (!firstTemplateParamType.isNull() && containsSalhelperReferenceObjectSubclass(firstTemplateParamType.getTypePtr()))
{
report(
DiagnosticsEngine::Warning,
"salhelper::SimpleReferenceObject subclass %0 being managed via smart pointer, should be managed via rtl::Reference, "
"parent is %1",
fieldDecl->getLocation())
<< fieldDecl->getSourceRange();