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>
19 // See 1d0bc2139759f087d50432f8a2116060676f34e1 "use std::experimental::source_location in
20 // uno::Exception" modification to
21 // workdir/UnoApiHeadersTarget/udkapi/normal/com/sun/star/uno/Exception.hdl, which is indirectly
22 // included through the above #include directives, in turn causing conditional inclusion of
23 // include/o3tl/runtimetooustring.hxx (and where `ok` is only read in an assert in !NDEBUG builds):
24 #if defined LIBO_USE_SOURCE_LOCATION
25 // expected-error@o3tl/runtimetooustring.hxx:* {{read s [loplugin:writeonlyvars]}}
26 // expected-error@o3tl/runtimetooustring.hxx:* {{write s [loplugin:writeonlyvars]}}
28 // expected-error@o3tl/runtimetooustring.hxx:* {{read ok [loplugin:writeonlyvars]}}
36 // check that we DON'T see reads here
37 // expected-error@+1 {{write m_bar3 [loplugin:writeonlyvars]}}
39 // expected-error@+1 {{write m_bar3b [loplugin:writeonlyvars]}}
42 m_bar3b
= m_bar3
= nullptr;
45 // check that we see reads of field when passed to a function pointer
46 // check that we see read of a field that is a function pointer
47 // expected-error@+2 {{write m_bar4 [loplugin:writeonlyvars]}}
48 // expected-error@+1 {{read m_bar4 [loplugin:writeonlyvars]}}
50 // expected-error@+1 {{read m_barfunctionpointer [loplugin:writeonlyvars]}}
51 void (*m_barfunctionpointer
)(int&) = nullptr;
52 m_barfunctionpointer(m_bar4
);
54 // check that we see reads of a field when used in variable init
55 // expected-error@+1 {{read m_bar5 [loplugin:writeonlyvars]}}
60 // check that we see reads of a field when used in ranged-for
61 // expected-error@+1 {{read m_bar6 [loplugin:writeonlyvars]}}
62 std::vector
<int> m_bar6
;
68 // check that we see writes of array fields
69 // expected-error@+1 {{write m_bar7 [loplugin:writeonlyvars]}}
73 // check that we see reads when a field is used in an array expression
74 // expected-error@+1 {{read m_bar8 [loplugin:writeonlyvars]}}
76 // expected-error@+1 {{read tmp [loplugin:writeonlyvars]}}
78 auto x2
= tmp
[m_bar8
];
81 // check that we don't see reads when calling operator>>=
82 // expected-error@+1 {{write m_bar9 [loplugin:writeonlyvars]}}
84 // expected-error@+1 {{read any [loplugin:writeonlyvars]}}
88 // check that we don't see writes when calling operator<<=
89 // expected-error@+1 {{read m_bar10 [loplugin:writeonlyvars]}}
90 sal_Int32 m_bar10
= 0;
91 // expected-error@+2 {{write any2 [loplugin:writeonlyvars]}}
92 // expected-error@+1 {{read any2 [loplugin:writeonlyvars]}}
104 namespace ReadOnlyAnalysis
110 // check that we see a write when we pass by non-const ref
111 // expected-error@+2 {{read m_f2 [loplugin:writeonlyvars]}}
112 // expected-error@+1 {{write m_f2 [loplugin:writeonlyvars]}}
116 // expected-error@+1 {{write m_f4 [loplugin:writeonlyvars]}}
117 std::vector
<int> m_f4
;
120 // check that we see a write when we pass by non-const ref
121 // expected-error@+2 {{read m_f5 [loplugin:writeonlyvars]}}
122 // expected-error@+1 {{write m_f5 [loplugin:writeonlyvars]}}
126 // check that we see a write when we pass by non-const ref
127 // expected-error@+2 {{read m_f6 [loplugin:writeonlyvars]}}
128 // expected-error@+1 {{write m_f6 [loplugin:writeonlyvars]}}
130 // expected-error@+1 {{write r [loplugin:writeonlyvars]}}
136 void ReadOnlyAnalysis3()
138 // expected-error@+1 {{read m_f1 [loplugin:writeonlyvars]}}
145 // Verify the special logic for container fields that only contains mutations that
147 void ReadOnlyAnalysis4()
149 // expected-error@+1 {{read m_readonly [loplugin:writeonlyvars]}}
150 std::vector
<int> m_readonly
;
151 // expected-error@+1 {{write m_writeonly [loplugin:writeonlyvars]}}
152 std::vector
<int> m_writeonly
;
153 // expected-error@+1 {{read m_readonlyCss [loplugin:writeonlyvars]}}
154 css::uno::Sequence
<sal_Int32
> m_readonlyCss
;
156 // expected-error@+1 {{write x [loplugin:writeonlyvars]}}
157 int x
= m_readonly
[0];
159 *m_readonly
.begin() = 1; // TODO?
161 m_writeonly
.push_back(0);
163 x
= m_readonlyCss
.getArray()[0];
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */