summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-09-14 15:57:11 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-09-17 17:24:52 +0200
commit8ad66ed2c5345f63e0581b6053222c80a9c612c3 (patch)
treebbfab2eae685b2a5906ee5b6cd67a9a9a1c1c3ee /compilerplugins
parent8f55b9fccda8abe690693d8630a9a52369f984ec (diff)
remove unnecessary dynamic_cast around SwXText
Unusually, we cannot use rtl::Reference to hold SwXText, because rtl::Reference assumes that its pointee is a subclass of OWeakObject, which SwXText is not (and we cannot make it so because the UNO bridge does not support virtual base classes). So we have to use css::uno::Reference<SwXText> and carve out an exception in loplugin:refcounting. Change-Id: If3a1307e30fdcd3b47aa665252be081fb5063400 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156982 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/refcounting.cxx42
1 files changed, 24 insertions, 18 deletions
diff --git a/compilerplugins/clang/refcounting.cxx b/compilerplugins/clang/refcounting.cxx
index ca6c0d97d9f0..801173ce6488 100644
--- a/compilerplugins/clang/refcounting.cxx
+++ b/compilerplugins/clang/refcounting.cxx
@@ -378,24 +378,30 @@ static bool containsStaticTypeMethod(const CXXRecordDecl* x)
void RefCounting::checkUnoReference(QualType qt, const Decl* decl, const RecordDecl* parent, const std::string& rDeclName)
{
- if (loplugin::TypeCheck(qt).Class("Reference").Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace()) {
- const CXXRecordDecl* pRecordDecl = qt->getAsCXXRecordDecl();
- const ClassTemplateSpecializationDecl* pTemplate = dyn_cast<ClassTemplateSpecializationDecl>(pRecordDecl);
- const TemplateArgument& rArg = pTemplate->getTemplateArgs()[0];
- const CXXRecordDecl* templateParam = rArg.getAsType()->getAsCXXRecordDecl()->getDefinition();
- if (templateParam && !containsStaticTypeMethod(templateParam)) {
- report(
- DiagnosticsEngine::Warning,
- ("uno::Reference %0 with template parameter that does not"
- " contain ::static_type() %1%select{|, parent is %3,}2 should"
- " probably be using rtl::Reference instead"),
- decl->getLocation())
- << rDeclName << qt << (parent != nullptr)
- << (parent != nullptr
- ? parent->getQualifiedNameAsString() : std::string())
- << decl->getSourceRange();
- }
- }
+ if (!loplugin::TypeCheck(qt).Class("Reference").Namespace("uno").Namespace("star").Namespace("sun").Namespace("com").GlobalNamespace())
+ return;
+ const CXXRecordDecl* pRecordDecl = qt->getAsCXXRecordDecl();
+ const ClassTemplateSpecializationDecl* pTemplate = dyn_cast<ClassTemplateSpecializationDecl>(pRecordDecl);
+ const TemplateArgument& rArg = pTemplate->getTemplateArgs()[0];
+ const CXXRecordDecl* templateParam = rArg.getAsType()->getAsCXXRecordDecl()->getDefinition();
+ if (!templateParam)
+ return;
+ // SwXText is a special case. It is a mixin class that does not inherit from OWeakObject, so
+ // we cannot use rtl::Reference.
+ if (loplugin::DeclCheck(templateParam).Class("SwXText"))
+ return;
+ if (containsStaticTypeMethod(templateParam))
+ return;
+ report(
+ DiagnosticsEngine::Warning,
+ ("uno::Reference %0 with template parameter that does not"
+ " contain ::static_type() %1%select{|, parent is %3,}2 should"
+ " probably be using rtl::Reference instead"),
+ decl->getLocation())
+ << rDeclName << qt << (parent != nullptr)
+ << (parent != nullptr
+ ? parent->getQualifiedNameAsString() : std::string())
+ << decl->getSourceRange();
}
bool RefCounting::visitTemporaryObjectExpr(Expr const * expr) {