summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
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: */