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/.
10 #if defined _WIN32 //TODO, see corresponding TODO in compilerplugins/clang/writeonlyvars.cxx
11 // expected-no-diagnostics
16 #include <com/sun/star/uno/Any.hxx>
17 #include <com/sun/star/uno/Sequence.hxx>
23 // check that we DON'T see reads here
24 // expected-error@+1 {{write m_bar3 [loplugin:writeonlyvars]}}
26 // expected-error@+1 {{write m_bar3b [loplugin:writeonlyvars]}}
29 m_bar3b
= m_bar3
= nullptr;
31 // check that we see reads of field when passed to a function pointer
32 // check that we see read of a field that is a function pointer
33 // expected-error@+2 {{write m_bar4 [loplugin:writeonlyvars]}}
34 // expected-error@+1 {{read m_bar4 [loplugin:writeonlyvars]}}
36 // expected-error@+1 {{read m_barfunctionpointer [loplugin:writeonlyvars]}}
37 void (*m_barfunctionpointer
)(int&) = nullptr;
38 m_barfunctionpointer(m_bar4
);
40 // check that we see reads of a field when used in variable init
41 // expected-error@+1 {{read m_bar5 [loplugin:writeonlyvars]}}
46 // check that we see reads of a field when used in ranged-for
47 // expected-error@+1 {{read m_bar6 [loplugin:writeonlyvars]}}
48 std::vector
<int> m_bar6
;
54 // check that we see writes of array fields
55 // expected-error@+1 {{write m_bar7 [loplugin:writeonlyvars]}}
59 // check that we see reads when a field is used in an array expression
60 // expected-error@+1 {{read m_bar8 [loplugin:writeonlyvars]}}
62 // expected-error@+1 {{read tmp [loplugin:writeonlyvars]}}
64 auto x2
= tmp
[m_bar8
];
67 // check that we don't see reads when calling operator>>=
68 // expected-error@+1 {{write m_bar9 [loplugin:writeonlyvars]}}
70 // expected-error@+1 {{read any [loplugin:writeonlyvars]}}
74 // check that we see don't see writes when calling operator<<=
75 // expected-error@+1 {{read m_bar10 [loplugin:writeonlyvars]}}
77 // expected-error@+2 {{write any2 [loplugin:writeonlyvars]}}
78 // expected-error@+1 {{read any2 [loplugin:writeonlyvars]}}
89 namespace ReadOnlyAnalysis
95 // check that we see a write when we pass by non-const ref
96 // expected-error@+2 {{read m_f2 [loplugin:writeonlyvars]}}
97 // expected-error@+1 {{write m_f2 [loplugin:writeonlyvars]}}
101 // expected-error@+1 {{write m_f4 [loplugin:writeonlyvars]}}
102 std::vector
<int> m_f4
;
105 // check that we see a write when we pass by non-const ref
106 // expected-error@+2 {{read m_f5 [loplugin:writeonlyvars]}}
107 // expected-error@+1 {{write m_f5 [loplugin:writeonlyvars]}}
111 // check that we see a write when we pass by non-const ref
112 // expected-error@+2 {{read m_f6 [loplugin:writeonlyvars]}}
113 // expected-error@+1 {{write m_f6 [loplugin:writeonlyvars]}}
115 // expected-error@+1 {{write r [loplugin:writeonlyvars]}}
121 void ReadOnlyAnalysis3()
123 // expected-error@+1 {{read m_f1 [loplugin:writeonlyvars]}}
130 // Verify the special logic for container fields that only contains mutations that
132 void ReadOnlyAnalysis4()
134 // expected-error@+1 {{read m_readonly [loplugin:writeonlyvars]}}
135 std::vector
<int> m_readonly
;
136 // expected-error@+1 {{write m_writeonly [loplugin:writeonlyvars]}}
137 std::vector
<int> m_writeonly
;
138 // expected-error@+1 {{read m_readonlyCss [loplugin:writeonlyvars]}}
139 css::uno::Sequence
<sal_Int32
> m_readonlyCss
;
141 // expected-error@+1 {{write x [loplugin:writeonlyvars]}}
142 int x
= m_readonly
[0];
144 *m_readonly
.begin() = 1; // TODO?
146 m_writeonly
.push_back(0);
148 x
= m_readonlyCss
.getArray()[0];
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */