diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-01-31 12:08:52 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-01-31 19:37:48 +0100 |
commit | de06f883e2ab53e5d74d480da7abb5c7dd33de3e (patch) | |
tree | d63697b67e57575222b38030ab082a59dcb1aa19 /compilerplugins/clang/test | |
parent | c599e23a92310916d4e7f09c5aaf354d63973d0b (diff) |
loplugin:unusedfields improve checking for fields guarded by existence check
which resulted in only a couple of real finds, mostly false+
Change-Id: I26058a29c27bff50e9526bedd54fb04589c2934d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87765
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/test')
-rw-r--r-- | compilerplugins/clang/test/unusedfields.cxx | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/unusedfields.cxx b/compilerplugins/clang/test/unusedfields.cxx index 2ec4ab815414..6efb17334e21 100644 --- a/compilerplugins/clang/test/unusedfields.cxx +++ b/compilerplugins/clang/test/unusedfields.cxx @@ -15,6 +15,8 @@ #include <ostream> #include <com/sun/star/uno/Any.hxx> #include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/XInterface.hpp> +#include <rtl/ref.hxx> struct Foo // expected-error@-1 {{read m_foo1 [loplugin:unusedfields]}} @@ -258,6 +260,41 @@ namespace WriteOnlyAnalysis3 }; }; +// Check that writes to fields that are wrapped by conditional checks are ignored, +// where those conditional checks use an 'operator bool' +namespace ReadOnlyAnalysis5 +{ + struct RefTarget + { + void acquire(); + void release(); + }; + struct Foo1 + // expected-error@-1 {{read m_field1 [loplugin:unusedfields]}} + // expected-error@-2 {{read m_field2 [loplugin:unusedfields]}} + // expected-error@-3 {{read m_field3xx [loplugin:unusedfields]}} + { + std::unique_ptr<int> m_field1; + rtl::Reference<RefTarget> m_field2; + css::uno::Reference<css::uno::XInterface> m_field3xx; + void f1(css::uno::Reference<css::uno::XInterface> a) + { + if (m_field1) + m_field1.reset(new int); + if (m_field1.get()) + m_field1.reset(new int); + if (m_field2) + m_field2 = new RefTarget; + if (m_field2.get()) + m_field2 = new RefTarget; + if (m_field3xx) + m_field3xx = a; + if (m_field3xx.get()) + m_field3xx = a; + } + }; +}; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |