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]}}
27 // expected-error@o3tl/safeint.hxx:* {{read res [loplugin:writeonlyvars]}}
29 // expected-error@o3tl/runtimetooustring.hxx:* {{read ok [loplugin:writeonlyvars]}}
37 // check that we DON'T see reads here
38 // expected-error@+1 {{write m_bar3 [loplugin:writeonlyvars]}}
40 // expected-error@+1 {{write m_bar3b [loplugin:writeonlyvars]}}
43 m_bar3b
= m_bar3
= nullptr;
46 // check that we see reads of field when passed to a function pointer
47 // check that we see read of a field that is a function pointer
48 // expected-error@+2 {{write m_bar4 [loplugin:writeonlyvars]}}
49 // expected-error@+1 {{read m_bar4 [loplugin:writeonlyvars]}}
51 // expected-error@+1 {{read m_barfunctionpointer [loplugin:writeonlyvars]}}
52 void (*m_barfunctionpointer
)(int&) = nullptr;
53 m_barfunctionpointer(m_bar4
);
55 // check that we see reads of a field when used in variable init
56 // expected-error@+1 {{read m_bar5 [loplugin:writeonlyvars]}}
61 // check that we see reads of a field when used in ranged-for
62 // expected-error@+1 {{read m_bar6 [loplugin:writeonlyvars]}}
63 std::vector
<int> m_bar6
;
69 // check that we see writes of array fields
70 // expected-error@+1 {{write m_bar7 [loplugin:writeonlyvars]}}
74 // check that we see reads when a field is used in an array expression
75 // expected-error@+1 {{read m_bar8 [loplugin:writeonlyvars]}}
77 // expected-error@+1 {{read tmp [loplugin:writeonlyvars]}}
79 auto x2
= tmp
[m_bar8
];
82 // check that we don't see reads when calling operator>>=
83 // expected-error@+1 {{write m_bar9 [loplugin:writeonlyvars]}}
85 // expected-error@+1 {{read any [loplugin:writeonlyvars]}}
89 // check that we don't see writes when calling operator<<=
90 // expected-error@+1 {{read m_bar10 [loplugin:writeonlyvars]}}
91 sal_Int32 m_bar10
= 0;
92 // expected-error@+2 {{write any2 [loplugin:writeonlyvars]}}
93 // expected-error@+1 {{read any2 [loplugin:writeonlyvars]}}
105 namespace ReadOnlyAnalysis
111 // check that we see a write when we pass by non-const ref
112 // expected-error@+2 {{read m_f2 [loplugin:writeonlyvars]}}
113 // expected-error@+1 {{write m_f2 [loplugin:writeonlyvars]}}
117 // expected-error@+1 {{write m_f4 [loplugin:writeonlyvars]}}
118 std::vector
<int> m_f4
;
121 // check that we see a write when we pass by non-const ref
122 // expected-error@+2 {{read m_f5 [loplugin:writeonlyvars]}}
123 // expected-error@+1 {{write m_f5 [loplugin:writeonlyvars]}}
127 // check that we see a write when we pass by non-const ref
128 // expected-error@+2 {{read m_f6 [loplugin:writeonlyvars]}}
129 // expected-error@+1 {{write m_f6 [loplugin:writeonlyvars]}}
131 // expected-error@+1 {{write r [loplugin:writeonlyvars]}}
137 void ReadOnlyAnalysis3()
139 // expected-error@+1 {{read m_f1 [loplugin:writeonlyvars]}}
146 // Verify the special logic for container fields that only contains mutations that
148 void ReadOnlyAnalysis4()
150 // expected-error@+1 {{read m_readonly [loplugin:writeonlyvars]}}
151 std::vector
<int> m_readonly
;
152 // expected-error@+1 {{write m_writeonly [loplugin:writeonlyvars]}}
153 std::vector
<int> m_writeonly
;
154 // expected-error@+1 {{read m_readonlyCss [loplugin:writeonlyvars]}}
155 css::uno::Sequence
<sal_Int32
> m_readonlyCss
;
157 // expected-error@+1 {{write x [loplugin:writeonlyvars]}}
158 int x
= m_readonly
[0];
160 *m_readonly
.begin() = 1; // TODO?
162 m_writeonly
.push_back(0);
164 x
= m_readonlyCss
.getArray()[0];
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */