diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-01-20 12:55:25 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-01-20 12:58:40 +0000 |
commit | 32c8b03f6172acf3a19c5d1938b9935369f536f1 (patch) | |
tree | 87c994cbbb77a1817ad7675ee712f75a6f4320b7 /compilerplugins/clang/test | |
parent | a5a1ea2f7d784c5c6c33f332ba61aceb7af3eca4 (diff) |
improve loplugin:refcounting
to catch places where we are converting a weak reference to a strong
reference, and then using a pointer to store the result
Change-Id: I69b132907b574e5c6974fadf18bd9658107d3a0d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145877
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/test')
-rw-r--r-- | compilerplugins/clang/test/refcounting.cxx | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/compilerplugins/clang/test/refcounting.cxx b/compilerplugins/clang/test/refcounting.cxx index 2b8ce94b42e6..54d4dbe14b38 100644 --- a/compilerplugins/clang/test/refcounting.cxx +++ b/compilerplugins/clang/test/refcounting.cxx @@ -107,11 +107,26 @@ void foo7() UnoSubObject* p3 = static_cast<UnoSubObject*>(getConstRef().get()); (void)p3; p3 = static_cast<UnoSubObject*>(getConstRef().get()); +} + +const unotools::WeakReference<UnoObject>& getWeakRef(); +void foo8() +{ + // expected-error@+1 {{weak object being converted to strong, and then the reference dropped, and managed via raw pointer, should be managed via rtl::Reference [loplugin:refcounting]}} + UnoSubObject* p1 = static_cast<UnoSubObject*>(getWeakRef().get().get()); + (void)p1; + + // expected-error@+1 {{weak object being converted to strong, and then the reference dropped, and managed via raw pointer, should be managed via rtl::Reference [loplugin:refcounting]}} + UnoObject* p2 = getWeakRef().get().get(); + (void)p2; - // no warning expected, although, arguably, we should be assigning to a rtl::Reference temporary unotools::WeakReference<UnoObject> weak1; - auto pTextObj = dynamic_cast<UnoSubObject*>(weak1.get().get()); - (void)pTextObj; -} + // expected-error@+1 {{weak object being converted to strong, and then the reference dropped, and managed via raw pointer, should be managed via rtl::Reference [loplugin:refcounting]}} + UnoSubObject* p3 = dynamic_cast<UnoSubObject*>(weak1.get().get()); + (void)p3; + // expected-error@+1 {{weak object being converted to strong, and then the reference dropped, and managed via raw pointer, should be managed via rtl::Reference [loplugin:refcounting]}} + UnoObject* p4 = weak1.get().get(); + (void)p4; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |