summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-05-08 14:33:47 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-05-08 18:32:33 +0200
commit11bdb6b9d9df991bb4ee48d4682458facaa2bdd5 (patch)
tree29180dbac55048e038c404769d059780f39f21a3 /compilerplugins
parentc69e5e3cc08bfbb4a5f6c756c523e4016c8fd1dd (diff)
improve loplugin:referencecasting
to catch a few more cases Change-Id: I0323fba51bb2b4ba255e1db5aa0d890c5c6a2e1b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93726 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/referencecasting.cxx14
-rw-r--r--compilerplugins/clang/test/referencecasting.cxx9
2 files changed, 23 insertions, 0 deletions
diff --git a/compilerplugins/clang/referencecasting.cxx b/compilerplugins/clang/referencecasting.cxx
index 1f8e13173811..33997cdb458d 100644
--- a/compilerplugins/clang/referencecasting.cxx
+++ b/compilerplugins/clang/referencecasting.cxx
@@ -329,6 +329,20 @@ static const RecordType* extractTemplateType(const clang::Type* cceType)
return recordType;
}
+ // extract Foo from Reference<Foo>
+ if (auto subst = dyn_cast<SubstTemplateTypeParmType>(cceType))
+ {
+ if (auto recType = dyn_cast<RecordType>(subst->desugar().getTypePtr()))
+ {
+ if (auto ctsd = dyn_cast<ClassTemplateSpecializationDecl>(recType->getDecl()))
+ {
+ auto const& args = ctsd->getTemplateArgs();
+ if (args.size() > 0 && args[0].getKind() == TemplateArgument::ArgKind::Type)
+ return dyn_cast_or_null<RecordType>(args[0].getAsType().getTypePtr());
+ }
+ }
+ }
+
if (auto elaboratedType = dyn_cast<ElaboratedType>(cceType))
cceType = elaboratedType->desugar().getTypePtr();
auto cceTST = dyn_cast<TemplateSpecializationType>(cceType);
diff --git a/compilerplugins/clang/test/referencecasting.cxx b/compilerplugins/clang/test/referencecasting.cxx
index 87324bb86fd6..0272bc89cc98 100644
--- a/compilerplugins/clang/test/referencecasting.cxx
+++ b/compilerplugins/clang/test/referencecasting.cxx
@@ -147,4 +147,13 @@ struct Test13
}
};
+void test14(css::uno::Sequence<css::uno::Reference<css::io::XStreamListener>> seq)
+{
+ for (sal_Int32 i = 0; i < seq.getLength(); ++i)
+ {
+ // expected-error@+1 {{the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]}}
+ css::uno::Reference<css::io::XStreamListener> xDataSeries(seq[i], css::uno::UNO_QUERY);
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */