1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #include <com/sun/star/uno/Any.hxx>
15 // expected-error@-1 {{read m_foo1 [loplugin:unusedfields]}}
21 // expected-error@-1 {{read m_bar2 [loplugin:unusedfields]}}
22 // expected-error@-2 {{read m_bar4 [loplugin:unusedfields]}}
23 // expected-error@-3 {{read m_bar5 [loplugin:unusedfields]}}
24 // expected-error@-4 {{read m_bar6 [loplugin:unusedfields]}}
25 // expected-error@-5 {{read m_barfunctionpointer [loplugin:unusedfields]}}
26 // expected-error@-6 {{read m_bar8 [loplugin:unusedfields]}}
27 // expected-error@-7 {{read m_bar10 [loplugin:unusedfields]}}
28 // expected-error@-8 {{write m_bar1 [loplugin:unusedfields]}}
29 // expected-error@-9 {{write m_bar2 [loplugin:unusedfields]}}
30 // expected-error@-10 {{write m_bar3 [loplugin:unusedfields]}}
31 // expected-error@-11 {{write m_bar3b [loplugin:unusedfields]}}
32 // expected-error@-12 {{write m_bar4 [loplugin:unusedfields]}}
33 // expected-error@-13 {{write m_bar7 [loplugin:unusedfields]}}
34 // expected-error@-14 {{write m_bar9 [loplugin:unusedfields]}}
41 void (*m_barfunctionpointer
)(int&);
43 std::vector
<int> m_bar6
;
50 // check that we see reads of fields like m_foo1 when referred to via constructor initializer
51 Bar(Foo
const & foo
) : m_bar1(foo
.m_foo1
) {}
53 // check that we don't see reads when inside copy/move constructor
54 Bar(Bar
const & other
) { m_bar3
= other
.m_bar3
; }
56 // check that we don't see reads when inside copy/move assignment operator
57 Bar
& operator=(Bar
const & other
) { m_bar3
= other
.m_bar3
; return *this; }
59 // check that we DON'T see reads here
60 int bar2() { return m_bar2
; }
62 // check that we DON'T see reads here
66 m_bar3b
= m_bar3
= nullptr;
69 // check that we see reads of field when passed to a function pointer
70 // check that we see read of a field that is a function pointer
71 void bar4() { m_barfunctionpointer(m_bar4
); }
73 // check that we see reads of a field when used in variable init
74 void bar5() { int x
= m_bar5
; (void) x
; }
76 // check that we see reads of a field when used in ranged-for
77 void bar6() { for (auto i
: m_bar6
) { (void)i
; } }
79 // check that we see don't see reads of array fields
80 void bar7() { m_bar7
[3] = 1; }
82 // check that we see reads when a field is used in an array expression
89 // check that we don't see reads when calling operator>>=
96 // check that we see don't see writes when calling operator<<=
104 // check that we __dont__ see a read of m_barstream
105 std::ostream
& operator<<(std::ostream
& s
, Bar
const & bar
)
107 s
<< bar
.m_barstream
;
111 struct ReadOnly1
{ ReadOnly1(int&); };
113 struct ReadOnlyAnalysis
114 // expected-error@-1 {{read m_f2 [loplugin:unusedfields]}}
115 // expected-error@-2 {{read m_f3 [loplugin:unusedfields]}}
116 // expected-error@-3 {{read m_f4 [loplugin:unusedfields]}}
117 // expected-error@-4 {{read m_f5 [loplugin:unusedfields]}}
118 // expected-error@-5 {{read m_f6 [loplugin:unusedfields]}}
119 // expected-error@-6 {{write m_f2 [loplugin:unusedfields]}}
120 // expected-error@-7 {{write m_f3 [loplugin:unusedfields]}}
121 // expected-error@-8 {{write m_f4 [loplugin:unusedfields]}}
122 // expected-error@-9 {{write m_f5 [loplugin:unusedfields]}}
123 // expected-error@-10 {{write m_f6 [loplugin:unusedfields]}}
128 std::vector
<int> m_f4
;
132 // check that we don't see a write of m_f1
133 ReadOnlyAnalysis() : m_f1(0) {}
137 // check that we see a write when we pass by non-const ref
138 void method2() { method1(m_f2
); }
140 int& method3() { return m_f3
; }
142 void method4() { m_f4
.push_back(1); }
144 // check that we see a write when we pass by non-const ref
145 void method5() { ReadOnly1
a(m_f5
); }
147 // check that we see a write when we pass by non-const ref
155 struct ReadOnlyAnalysis2
156 // expected-error@-1 {{write m_r2f1 [loplugin:unusedfields]}}
161 ReadOnlyAnalysis2 global
{ 1 };
163 struct ReadOnlyAnalysis3
164 // expected-error@-1 {{read m_f1 [loplugin:unusedfields]}}
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */