diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-08-23 10:15:01 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-08-23 15:25:26 +0200 |
commit | 8a54339fc83fe9abaaace6f9f374697e6923d684 (patch) | |
tree | 516e82bb9eca2d586aa7acebbe369f67ff707a7f /compilerplugins | |
parent | d34f1df73806e9ca05fa0d07da619e2c0f01b6f7 (diff) |
loplugin:referencecasting look through more clang Types
Note that because of where the fix resides, loplugin:redundantcast
also notices a few more things.
Change-Id: I0b66047fadfff2c5ceafcbd3eab085de00d861a6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120865
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/plugin.cxx | 16 | ||||
-rw-r--r-- | compilerplugins/clang/test/referencecasting.cxx | 22 |
2 files changed, 36 insertions, 2 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index c68eceb67c32..6f7c464aa161 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -11,6 +11,7 @@ #include "plugin.hxx" +#include <iostream> #include <cassert> #include <cstddef> #include <string> @@ -736,8 +737,19 @@ bool hasCLanguageLinkageType(FunctionDecl const * decl) { static const CXXRecordDecl* stripTypeSugar(QualType qt) { const clang::Type* t = qt.getTypePtr(); - while (auto elaboratedType = dyn_cast<ElaboratedType>(t)) - t = elaboratedType->desugar().getTypePtr(); + do + { + if (auto elaboratedType = dyn_cast<ElaboratedType>(t)) + t = elaboratedType->desugar().getTypePtr(); + else if (auto tsType = dyn_cast<TemplateSpecializationType>(t)) + t = tsType->desugar().getTypePtr(); + else if (auto sttpType = dyn_cast<SubstTemplateTypeParmType>(t)) + t = sttpType->desugar().getTypePtr(); + else if (auto tdType = dyn_cast<TypedefType>(t)) + t = tdType->desugar().getTypePtr(); + else + break; + } while(true); auto recordType = dyn_cast<RecordType>(t); if (!recordType) return nullptr; diff --git a/compilerplugins/clang/test/referencecasting.cxx b/compilerplugins/clang/test/referencecasting.cxx index a6850ed660ea..1b1e75f90cea 100644 --- a/compilerplugins/clang/test/referencecasting.cxx +++ b/compilerplugins/clang/test/referencecasting.cxx @@ -13,8 +13,10 @@ #include "com/sun/star/uno/Sequence.hxx" #include "com/sun/star/uno/XInterface.hpp" #include "com/sun/star/io/XStreamListener.hpp" +#include "com/sun/star/io/XInputStream.hpp" #include "com/sun/star/lang/XTypeProvider.hpp" #include "com/sun/star/lang/XComponent.hpp" +#include "cppuhelper/implbase.hxx" #include "cppuhelper/weak.hxx" #include "rtl/ref.hxx" @@ -192,4 +194,24 @@ void test14(css::uno::Sequence<css::uno::Reference<css::io::XStreamListener>> se } } +namespace test15 +{ +class Foo : public cppu::WeakImplHelper<css::lang::XComponent, css::io::XInputStream> +{ + virtual ~Foo(); + css::uno::Reference<css::lang::XTypeProvider> bar() + { + // expected-error@+1 {{the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]}} + return css::uno::Reference<css::lang::XTypeProvider>( + static_cast<css::lang::XTypeProvider*>(this), css::uno::UNO_QUERY); + } + css::uno::Reference<css::io::XInputStream> bar2() + { + // expected-error@+1 {{the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]}} + return css::uno::Reference<css::io::XInputStream>(static_cast<css::io::XInputStream*>(this), + css::uno::UNO_QUERY); + } +}; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |