summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/test/unusedfields.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-06-29 10:42:17 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-06-29 11:00:57 +0200
commit4cc2fc6cef4f76c1d203666cb5e47b5d70ec7be5 (patch)
tree76ef278f39f717bf89ec109ac4704d5f9ddf3dc5 /compilerplugins/clang/test/unusedfields.cxx
parent98befbb26217b0bf3f35354e418a355280c52cfc (diff)
unusedfields loplugin writeonly analysis improvements
(1) ignore reads inside copy/move constructors/operator= (2) fix false+ when assigning to array field (3) ignore reference ("&") fields Change-Id: I69a1a1c567a0b28a783e605982e5150811b6cc4a
Diffstat (limited to 'compilerplugins/clang/test/unusedfields.cxx')
-rw-r--r--compilerplugins/clang/test/unusedfields.cxx28
1 files changed, 20 insertions, 8 deletions
diff --git a/compilerplugins/clang/test/unusedfields.cxx b/compilerplugins/clang/test/unusedfields.cxx
index 1d43c81ea177..a66b7a6e7eca 100644
--- a/compilerplugins/clang/test/unusedfields.cxx
+++ b/compilerplugins/clang/test/unusedfields.cxx
@@ -17,29 +17,39 @@ struct Foo
struct Bar
// expected-error@-1 {{read m_bar2 [loplugin:unusedfields]}}
-// expected-error@-2 {{read m_bar3 [loplugin:unusedfields]}}
-// expected-error@-3 {{read m_bar4 [loplugin:unusedfields]}}
-// expected-error@-4 {{read m_bar5 [loplugin:unusedfields]}}
-// expected-error@-5 {{read m_bar6 [loplugin:unusedfields]}}
-// expected-error@-6 {{read m_barfunctionpointer [loplugin:unusedfields]}}
+// expected-error@-2 {{read m_bar4 [loplugin:unusedfields]}}
+// expected-error@-3 {{read m_bar5 [loplugin:unusedfields]}}
+// expected-error@-4 {{read m_bar6 [loplugin:unusedfields]}}
+// expected-error@-5 {{read m_barfunctionpointer [loplugin:unusedfields]}}
{
int m_bar1;
int m_bar2 = 1;
int* m_bar3;
+ int* m_bar3b;
int m_bar4;
void (*m_barfunctionpointer)(int&);
int m_bar5;
std::vector<int> m_bar6;
+ int m_bar7[5];
- //check that we see reads of fields when referred to via constructor initializer
+ // check that we see reads of fields like m_foo1 when referred to via constructor initializer
Bar(Foo const & foo) : m_bar1(foo.m_foo1) {}
+ // check that we don't see reads when inside copy/move constructor
+ Bar(Bar const & other) { m_bar3 = other.m_bar3; }
+
+ // check that we don't see reads when inside copy/move assignment operator
+ Bar& operator=(Bar const & other) { m_bar3 = other.m_bar3; return *this; }
+
// check that we DONT see reads here
int bar2() { return m_bar2; }
// check that we DONT see reads here
- void bar3() { *m_bar3 = 2; }
- void bar3b() { m_bar3 = nullptr; }
+ void bar3()
+ {
+ m_bar3 = nullptr;
+ m_bar3b = m_bar3 = nullptr;
+ }
// check that we see reads of field when passed to a function pointer
// check that we see read of a field that is a function pointer
@@ -50,6 +60,8 @@ struct Bar
// check that we see reads of a field when used in ranged-for
void bar6() { for (auto i : m_bar6) { (void)i; } }
+
+ void bar7() { m_bar7[3] = 1; }
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */