diff options
Diffstat (limited to 'compilerplugins/clang/test/referencecasting.cxx')
-rw-r--r-- | compilerplugins/clang/test/referencecasting.cxx | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/referencecasting.cxx b/compilerplugins/clang/test/referencecasting.cxx index 0272bc89cc98..beb69cc86616 100644 --- a/compilerplugins/clang/test/referencecasting.cxx +++ b/compilerplugins/clang/test/referencecasting.cxx @@ -9,16 +9,22 @@ #include "sal/config.h" +#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" void test1(const css::uno::Reference<css::io::XStreamListener>& a) { // expected-error@+1 {{the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]}} css::uno::Reference<css::lang::XEventListener> b(a, css::uno::UNO_QUERY); + // expected-error@+1 {{the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]}} + auto c = css::uno::Reference<css::lang::XEventListener>::query(a); } namespace test2 @@ -77,6 +83,33 @@ void test(css::uno::Reference<css::io::XStreamListener> l) // expected-error@+1 {{unnecessary get() call [loplugin:referencecasting]}} a.set(l.get(), css::uno::UNO_QUERY); } + +class FooStream : public css::io::XStreamListener +{ + virtual ~FooStream(); +}; +void test(rtl::Reference<FooStream> l) +{ + // expected-error@+1 {{unnecessary get() call [loplugin:referencecasting]}} + css::uno::Reference<css::io::XStreamListener> a(l.get()); + // expected-error@+1 {{the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]}} + a.set(l.get(), css::uno::UNO_QUERY); + // expected-error@+1 {{unnecessary get() call [loplugin:referencecasting]}} + a.set(l.get()); + // expected-error@+1 {{the source reference is already a subtype of the destination reference, just use = [loplugin:referencecasting]}} + css::uno::Reference<css::io::XStreamListener> b(l.get(), css::uno::UNO_QUERY); + // no warning expected + css::uno::Reference<css::lang::XTypeProvider> c(l.get(), css::uno::UNO_QUERY); + // no warning expected + css::uno::Reference<css::io::XStreamListener> a2 = l; + (void)a2; +} +css::uno::Sequence<css::uno::Reference<css::io::XStreamListener>> getContinuations() +{ + rtl::Reference<FooStream> noel1; + // expected-error@+1 {{unnecessary get() call [loplugin:referencecasting]}} + return { noel1.get() }; +} } namespace test8 @@ -156,4 +189,29 @@ 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); + } + css::uno::Reference<css::io::XInputStream> bar3() + { + // 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>(*this, css::uno::UNO_QUERY); + } +}; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |