1ea563daaSAdam Balogh // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,debug.DebugIteratorModeling,debug.ExprInspection -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=false %s -verify -analyzer-config display-checker-name=false
2eb90692dSAdam Balogh
3ea563daaSAdam Balogh // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,debug.DebugIteratorModeling,debug.ExprInspection -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify -analyzer-config display-checker-name=false
4eb90692dSAdam Balogh
5ea563daaSAdam Balogh // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,debug.DebugIteratorModeling,debug.ExprInspection -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 -DSTD_ADVANCE_INLINE_LEVEL=0 %s -verify -analyzer-config display-checker-name=false
6eb90692dSAdam Balogh
7ea563daaSAdam Balogh // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,debug.DebugIteratorModeling,debug.ExprInspection -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 -DSTD_ADVANCE_INLINE_LEVEL=1 %s -verify -analyzer-config display-checker-name=false
8eb90692dSAdam Balogh
9ea563daaSAdam Balogh // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,debug.DebugIteratorModeling,debug.ExprInspection -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 -DSTD_ADVANCE_INLINE_LEVEL=2 %s -verify -analyzer-config display-checker-name=false
10eb90692dSAdam Balogh
11eb90692dSAdam Balogh // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorModeling,debug.ExprInspection -analyzer-config aggressive-binary-operation-simplification=true %s 2>&1 | FileCheck %s
12eb90692dSAdam Balogh
13eb90692dSAdam Balogh #include "Inputs/system-header-simulator-cxx.h"
14eb90692dSAdam Balogh
15eb90692dSAdam Balogh template <typename Container>
16eb90692dSAdam Balogh long clang_analyzer_container_begin(const Container&);
17eb90692dSAdam Balogh template <typename Container>
18eb90692dSAdam Balogh long clang_analyzer_container_end(const Container&);
19eb90692dSAdam Balogh template <typename Iterator>
20eb90692dSAdam Balogh long clang_analyzer_iterator_position(const Iterator&);
219e63b190SAdam Balogh long clang_analyzer_iterator_position(int*);
22eb90692dSAdam Balogh template <typename Iterator>
23eb90692dSAdam Balogh void* clang_analyzer_iterator_container(const Iterator&);
24eb90692dSAdam Balogh template <typename Iterator>
25eb90692dSAdam Balogh bool clang_analyzer_iterator_validity(const Iterator&);
26eb90692dSAdam Balogh
27eb90692dSAdam Balogh void clang_analyzer_denote(long, const char*);
28eb90692dSAdam Balogh void clang_analyzer_express(long);
29eb90692dSAdam Balogh void clang_analyzer_eval(bool);
30eb90692dSAdam Balogh void clang_analyzer_warnIfReached();
31eb90692dSAdam Balogh
begin(const std::vector<int> & v)32eb90692dSAdam Balogh void begin(const std::vector<int> &v) {
33eb90692dSAdam Balogh auto i = v.begin();
34eb90692dSAdam Balogh
35eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i) == &v); // expected-warning{{TRUE}}
36eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
37ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin(){{$}}}}
38eb90692dSAdam Balogh
39eb90692dSAdam Balogh if (i != v.begin()) {
40eb90692dSAdam Balogh clang_analyzer_warnIfReached();
41eb90692dSAdam Balogh }
42eb90692dSAdam Balogh }
43eb90692dSAdam Balogh
end(const std::vector<int> & v)44eb90692dSAdam Balogh void end(const std::vector<int> &v) {
45eb90692dSAdam Balogh auto i = v.end();
46eb90692dSAdam Balogh
47eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i) == &v); // expected-warning{{TRUE}}
48eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
49ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end(){{$}}}}
50eb90692dSAdam Balogh
51eb90692dSAdam Balogh if (i != v.end()) {
52eb90692dSAdam Balogh clang_analyzer_warnIfReached();
53eb90692dSAdam Balogh }
54eb90692dSAdam Balogh }
55eb90692dSAdam Balogh
prefix_increment(const std::vector<int> & v)56eb90692dSAdam Balogh void prefix_increment(const std::vector<int> &v) {
57eb90692dSAdam Balogh auto i = v.begin();
58eb90692dSAdam Balogh
59eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
60eb90692dSAdam Balogh
61eb90692dSAdam Balogh auto j = ++i;
62eb90692dSAdam Balogh
63ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin() + 1{{$}}}}
64ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.begin() + 1{{$}}}}
65eb90692dSAdam Balogh }
66eb90692dSAdam Balogh
prefix_decrement(const std::vector<int> & v)67eb90692dSAdam Balogh void prefix_decrement(const std::vector<int> &v) {
68eb90692dSAdam Balogh auto i = v.end();
69eb90692dSAdam Balogh
70eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
71eb90692dSAdam Balogh
72eb90692dSAdam Balogh auto j = --i;
73eb90692dSAdam Balogh
74ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end() - 1{{$}}}}
75ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.end() - 1{{$}}}}
76eb90692dSAdam Balogh }
77eb90692dSAdam Balogh
postfix_increment(const std::vector<int> & v)78eb90692dSAdam Balogh void postfix_increment(const std::vector<int> &v) {
79eb90692dSAdam Balogh auto i = v.begin();
80eb90692dSAdam Balogh
81eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
82eb90692dSAdam Balogh
83eb90692dSAdam Balogh auto j = i++;
84eb90692dSAdam Balogh
85ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin() + 1{{$}}}}
86ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.begin(){{$}}}}
87eb90692dSAdam Balogh }
88eb90692dSAdam Balogh
postfix_decrement(const std::vector<int> & v)89eb90692dSAdam Balogh void postfix_decrement(const std::vector<int> &v) {
90eb90692dSAdam Balogh auto i = v.end();
91eb90692dSAdam Balogh
92eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
93eb90692dSAdam Balogh
94eb90692dSAdam Balogh auto j = i--;
95eb90692dSAdam Balogh
96ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end() - 1{{$}}}}
97ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.end(){{$}}}}
98eb90692dSAdam Balogh }
99eb90692dSAdam Balogh
plus_equal(const std::vector<int> & v)100eb90692dSAdam Balogh void plus_equal(const std::vector<int> &v) {
101eb90692dSAdam Balogh auto i = v.begin();
102eb90692dSAdam Balogh
103eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
104eb90692dSAdam Balogh
105eb90692dSAdam Balogh i += 2;
106eb90692dSAdam Balogh
107ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin() + 2{{$}}}}
108eb90692dSAdam Balogh }
109eb90692dSAdam Balogh
plus_equal_negative(const std::vector<int> & v)110eb90692dSAdam Balogh void plus_equal_negative(const std::vector<int> &v) {
111eb90692dSAdam Balogh auto i = v.end();
112eb90692dSAdam Balogh
113eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
114eb90692dSAdam Balogh
115eb90692dSAdam Balogh i += -2;
116eb90692dSAdam Balogh
117ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end() - 2{{$}}}}
118eb90692dSAdam Balogh }
119eb90692dSAdam Balogh
minus_equal(const std::vector<int> & v)120eb90692dSAdam Balogh void minus_equal(const std::vector<int> &v) {
121eb90692dSAdam Balogh auto i = v.end();
122eb90692dSAdam Balogh
123eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
124eb90692dSAdam Balogh
125eb90692dSAdam Balogh i -= 2;
126eb90692dSAdam Balogh
127ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end() - 2{{$}}}}
128eb90692dSAdam Balogh }
129eb90692dSAdam Balogh
minus_equal_negative(const std::vector<int> & v)130eb90692dSAdam Balogh void minus_equal_negative(const std::vector<int> &v) {
131eb90692dSAdam Balogh auto i = v.begin();
132eb90692dSAdam Balogh
133eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
134eb90692dSAdam Balogh
135eb90692dSAdam Balogh i -= -2;
136eb90692dSAdam Balogh
137ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin() + 2{{$}}}}
138eb90692dSAdam Balogh }
139eb90692dSAdam Balogh
copy(const std::vector<int> & v)140eb90692dSAdam Balogh void copy(const std::vector<int> &v) {
141eb90692dSAdam Balogh auto i1 = v.end();
142eb90692dSAdam Balogh
143eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
144eb90692dSAdam Balogh
145eb90692dSAdam Balogh auto i2 = i1;
146eb90692dSAdam Balogh
147eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
148ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end(){{$}}}}
149ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end(){{$}}}}
150eb90692dSAdam Balogh }
151eb90692dSAdam Balogh
plus_lhs(const std::vector<int> & v)152*141cb8a1SEndre Fülöp void plus_lhs(const std::vector<int> &v) {
153eb90692dSAdam Balogh auto i1 = v.begin();
154eb90692dSAdam Balogh
155eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
156eb90692dSAdam Balogh
157eb90692dSAdam Balogh auto i2 = i1 + 2;
158eb90692dSAdam Balogh
159eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
160ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re{{$v.begin(){{$}}}}
161ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re{{$v.begin() + 2{{$}}}}
162eb90692dSAdam Balogh }
163eb90692dSAdam Balogh
plus_rhs(const std::vector<int> & v)164*141cb8a1SEndre Fülöp void plus_rhs(const std::vector<int> &v) {
165*141cb8a1SEndre Fülöp auto i1 = v.begin();
166*141cb8a1SEndre Fülöp
167*141cb8a1SEndre Fülöp clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
168*141cb8a1SEndre Fülöp
169*141cb8a1SEndre Fülöp auto i2 = 2 + i1;
170*141cb8a1SEndre Fülöp
171*141cb8a1SEndre Fülöp clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
172*141cb8a1SEndre Fülöp clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re{{$v.begin(){{$}}}}
173*141cb8a1SEndre Fülöp clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re{{$v.begin() + 2{{$}}}}
174*141cb8a1SEndre Fülöp }
175*141cb8a1SEndre Fülöp
plus_lhs_negative(const std::vector<int> & v)176*141cb8a1SEndre Fülöp void plus_lhs_negative(const std::vector<int> &v) {
177eb90692dSAdam Balogh auto i1 = v.end();
178eb90692dSAdam Balogh
179eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
180eb90692dSAdam Balogh
181eb90692dSAdam Balogh auto i2 = i1 + (-2);
182eb90692dSAdam Balogh
183eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
184ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end(){{$}}}}
185ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end() - 2{{$}}}}
186eb90692dSAdam Balogh }
187eb90692dSAdam Balogh
plus_rhs_negative(const std::vector<int> & v)188*141cb8a1SEndre Fülöp void plus_rhs_negative(const std::vector<int> &v) {
189*141cb8a1SEndre Fülöp auto i1 = v.end();
190*141cb8a1SEndre Fülöp
191*141cb8a1SEndre Fülöp clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
192*141cb8a1SEndre Fülöp
193*141cb8a1SEndre Fülöp auto i2 = (-2) + i1;
194*141cb8a1SEndre Fülöp
195*141cb8a1SEndre Fülöp clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
196*141cb8a1SEndre Fülöp clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end(){{$}}}}
197*141cb8a1SEndre Fülöp clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end() - 2{{$}}}}
198*141cb8a1SEndre Fülöp }
199*141cb8a1SEndre Fülöp
minus(const std::vector<int> & v)200eb90692dSAdam Balogh void minus(const std::vector<int> &v) {
201eb90692dSAdam Balogh auto i1 = v.end();
202eb90692dSAdam Balogh
203eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
204eb90692dSAdam Balogh
205eb90692dSAdam Balogh auto i2 = i1 - 2;
206eb90692dSAdam Balogh
207eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
208ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end(){{$}}}}
209ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end() - 2{{$}}}}
210eb90692dSAdam Balogh }
211eb90692dSAdam Balogh
minus_negative(const std::vector<int> & v)212eb90692dSAdam Balogh void minus_negative(const std::vector<int> &v) {
213eb90692dSAdam Balogh auto i1 = v.begin();
214eb90692dSAdam Balogh
215eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
216eb90692dSAdam Balogh
217eb90692dSAdam Balogh auto i2 = i1 - (-2);
218eb90692dSAdam Balogh
219eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
220ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.begin(){{$}}}}
221ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.begin() + 2{{$}}}}
222eb90692dSAdam Balogh }
223eb90692dSAdam Balogh
copy_and_increment1(const std::vector<int> & v)224eb90692dSAdam Balogh void copy_and_increment1(const std::vector<int> &v) {
225eb90692dSAdam Balogh auto i1 = v.begin();
226eb90692dSAdam Balogh
227eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
228eb90692dSAdam Balogh
229eb90692dSAdam Balogh auto i2 = i1;
230eb90692dSAdam Balogh ++i1;
231eb90692dSAdam Balogh
232ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.begin() + 1{{$}}}}
233ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.begin(){{$}}}}
234eb90692dSAdam Balogh }
235eb90692dSAdam Balogh
copy_and_increment2(const std::vector<int> & v)236eb90692dSAdam Balogh void copy_and_increment2(const std::vector<int> &v) {
237eb90692dSAdam Balogh auto i1 = v.begin();
238eb90692dSAdam Balogh
239eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
240eb90692dSAdam Balogh
241eb90692dSAdam Balogh auto i2 = i1;
242eb90692dSAdam Balogh ++i2;
243eb90692dSAdam Balogh
244ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.begin(){{$}}}}
245ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.begin() + 1{{$}}}}
246eb90692dSAdam Balogh }
247eb90692dSAdam Balogh
copy_and_decrement1(const std::vector<int> & v)248eb90692dSAdam Balogh void copy_and_decrement1(const std::vector<int> &v) {
249eb90692dSAdam Balogh auto i1 = v.end();
250eb90692dSAdam Balogh
251eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
252eb90692dSAdam Balogh
253eb90692dSAdam Balogh auto i2 = i1;
254eb90692dSAdam Balogh --i1;
255eb90692dSAdam Balogh
256ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end() - 1{{$}}}}
257ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end(){{$}}}}
258eb90692dSAdam Balogh }
259eb90692dSAdam Balogh
copy_and_decrement2(const std::vector<int> & v)260eb90692dSAdam Balogh void copy_and_decrement2(const std::vector<int> &v) {
261eb90692dSAdam Balogh auto i1 = v.end();
262eb90692dSAdam Balogh
263eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
264eb90692dSAdam Balogh
265eb90692dSAdam Balogh auto i2 = i1;
266eb90692dSAdam Balogh --i2;
267eb90692dSAdam Balogh
268ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end(){{$}}}}
269ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end() - 1{{$}}}}
270eb90692dSAdam Balogh }
271eb90692dSAdam Balogh
272eb90692dSAdam Balogh /// std::advance(), std::prev(), std::next()
273eb90692dSAdam Balogh
std_advance_minus(const std::vector<int> & v)274eb90692dSAdam Balogh void std_advance_minus(const std::vector<int> &v) {
275eb90692dSAdam Balogh auto i = v.end();
276eb90692dSAdam Balogh
277eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
278eb90692dSAdam Balogh
279eb90692dSAdam Balogh std::advance(i, -1);
280eb90692dSAdam Balogh
281ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end() - 1{{$}}}}
282eb90692dSAdam Balogh }
283eb90692dSAdam Balogh
std_advance_plus(const std::vector<int> & v)284eb90692dSAdam Balogh void std_advance_plus(const std::vector<int> &v) {
285eb90692dSAdam Balogh auto i = v.begin();
286eb90692dSAdam Balogh
287eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
288eb90692dSAdam Balogh
289eb90692dSAdam Balogh std::advance(i, 1);
290eb90692dSAdam Balogh
291ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin() + 1{{$}}}}
292eb90692dSAdam Balogh }
293eb90692dSAdam Balogh
std_prev(const std::vector<int> & v)294eb90692dSAdam Balogh void std_prev(const std::vector<int> &v) {
295eb90692dSAdam Balogh auto i = v.end();
296eb90692dSAdam Balogh
297eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
298eb90692dSAdam Balogh
299eb90692dSAdam Balogh auto j = std::prev(i);
300eb90692dSAdam Balogh
301ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.end() - 1{{$}}}}
302eb90692dSAdam Balogh }
303eb90692dSAdam Balogh
std_prev2(const std::vector<int> & v)304eb90692dSAdam Balogh void std_prev2(const std::vector<int> &v) {
305eb90692dSAdam Balogh auto i = v.end();
306eb90692dSAdam Balogh
307eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
308eb90692dSAdam Balogh
309eb90692dSAdam Balogh auto j = std::prev(i, 2);
310eb90692dSAdam Balogh
311ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.end() - 2{{$}}}}
312eb90692dSAdam Balogh }
313eb90692dSAdam Balogh
std_next(const std::vector<int> & v)314eb90692dSAdam Balogh void std_next(const std::vector<int> &v) {
315eb90692dSAdam Balogh auto i = v.begin();
316eb90692dSAdam Balogh
317eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
318eb90692dSAdam Balogh
319eb90692dSAdam Balogh auto j = std::next(i);
320eb90692dSAdam Balogh
321ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.begin() + 1{{$}}}}
322eb90692dSAdam Balogh }
323eb90692dSAdam Balogh
std_next2(const std::vector<int> & v)324eb90692dSAdam Balogh void std_next2(const std::vector<int> &v) {
325eb90692dSAdam Balogh auto i = v.begin();
326eb90692dSAdam Balogh
327eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
328eb90692dSAdam Balogh
329eb90692dSAdam Balogh auto j = std::next(i, 2);
330eb90692dSAdam Balogh
331ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.begin() + 2{{$}}}}
332eb90692dSAdam Balogh }
333eb90692dSAdam Balogh
334eb90692dSAdam Balogh ////////////////////////////////////////////////////////////////////////////////
335eb90692dSAdam Balogh ///
336eb90692dSAdam Balogh /// C O N T A I N E R A S S I G N M E N T S
337eb90692dSAdam Balogh ///
338eb90692dSAdam Balogh ////////////////////////////////////////////////////////////////////////////////
339eb90692dSAdam Balogh
340eb90692dSAdam Balogh // Copy
341eb90692dSAdam Balogh
list_copy_assignment(std::list<int> & L1,const std::list<int> & L2)342eb90692dSAdam Balogh void list_copy_assignment(std::list<int> &L1, const std::list<int> &L2) {
343eb90692dSAdam Balogh auto i0 = L1.cbegin();
344eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
345eb90692dSAdam Balogh L1 = L2;
346eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
347eb90692dSAdam Balogh }
348eb90692dSAdam Balogh
vector_copy_assignment(std::vector<int> & V1,const std::vector<int> & V2)349eb90692dSAdam Balogh void vector_copy_assignment(std::vector<int> &V1, const std::vector<int> &V2) {
350eb90692dSAdam Balogh auto i0 = V1.cbegin();
351eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
352eb90692dSAdam Balogh V1 = V2;
353eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
354eb90692dSAdam Balogh }
355eb90692dSAdam Balogh
deque_copy_assignment(std::deque<int> & D1,const std::deque<int> & D2)356eb90692dSAdam Balogh void deque_copy_assignment(std::deque<int> &D1, const std::deque<int> &D2) {
357eb90692dSAdam Balogh auto i0 = D1.cbegin();
358eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
359eb90692dSAdam Balogh D1 = D2;
360eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
361eb90692dSAdam Balogh }
362eb90692dSAdam Balogh
forward_list_copy_assignment(std::forward_list<int> & FL1,const std::forward_list<int> & FL2)363eb90692dSAdam Balogh void forward_list_copy_assignment(std::forward_list<int> &FL1,
364eb90692dSAdam Balogh const std::forward_list<int> &FL2) {
365eb90692dSAdam Balogh auto i0 = FL1.cbegin();
366eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
367eb90692dSAdam Balogh FL1 = FL2;
368eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
369eb90692dSAdam Balogh }
370eb90692dSAdam Balogh
371eb90692dSAdam Balogh // Move
372eb90692dSAdam Balogh
list_move_assignment(std::list<int> & L1,std::list<int> & L2)373eb90692dSAdam Balogh void list_move_assignment(std::list<int> &L1, std::list<int> &L2) {
374eb90692dSAdam Balogh auto i0 = L1.cbegin(), i1 = L2.cbegin(), i2 = --L2.cend(), i3 = L2.cend();
375eb90692dSAdam Balogh
376eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L2), "$L2.begin()");
377eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L2), "$L2.end()");
378eb90692dSAdam Balogh
379eb90692dSAdam Balogh L1 = std::move(L2);
380eb90692dSAdam Balogh
381eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
382eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
383eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
384eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i3)); //expected-warning{{TRUE}} FIXME: Should be FALSE.
385eb90692dSAdam Balogh
386eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i1) == &L1); // expected-warning{{TRUE}}
387eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &L1); // expected-warning{{TRUE}}
388eb90692dSAdam Balogh
389ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L2.begin(){{$}}}}
390eb90692dSAdam Balogh }
391eb90692dSAdam Balogh
vector_move_assignment(std::vector<int> & V1,std::vector<int> & V2)392eb90692dSAdam Balogh void vector_move_assignment(std::vector<int> &V1, std::vector<int> &V2) {
393eb90692dSAdam Balogh auto i0 = V1.cbegin(), i1 = V2.cbegin(), i2 = --V2.cend(), i3 = V2.cend();
394eb90692dSAdam Balogh
395eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V2), "$V2.begin()");
396eb90692dSAdam Balogh
397eb90692dSAdam Balogh V1 = std::move(V2);
398eb90692dSAdam Balogh
399eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
400eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
401eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
402eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i3)); //expected-warning{{TRUE}} FIXME: Should be FALSE.
403eb90692dSAdam Balogh
404eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i1) == &V1); // expected-warning{{TRUE}}
405eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &V1); // expected-warning{{TRUE}}
406eb90692dSAdam Balogh
407ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V2.begin(){{$}}}}
408eb90692dSAdam Balogh }
409eb90692dSAdam Balogh
deque_move_assignment(std::deque<int> & D1,std::deque<int> & D2)410eb90692dSAdam Balogh void deque_move_assignment(std::deque<int> &D1, std::deque<int> &D2) {
411eb90692dSAdam Balogh auto i0 = D1.cbegin(), i1 = D2.cbegin(), i2 = --D2.cend(), i3 = D2.cend();
412eb90692dSAdam Balogh
413eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D2), "$D2.begin()");
414eb90692dSAdam Balogh
415eb90692dSAdam Balogh D1 = std::move(D2);
416eb90692dSAdam Balogh
417eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
418eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
419eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
420eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i3)); //expected-warning{{TRUE}} FIXME: Should be FALSE.
421eb90692dSAdam Balogh
422eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i1) == &D1); // expected-warning{{TRUE}}
423eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &D1); // expected-warning{{TRUE}}
424eb90692dSAdam Balogh
425ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$D2.begin(){{$}}}}
426eb90692dSAdam Balogh }
427eb90692dSAdam Balogh
forward_list_move_assignment(std::forward_list<int> & FL1,std::forward_list<int> & FL2)428eb90692dSAdam Balogh void forward_list_move_assignment(std::forward_list<int> &FL1,
429eb90692dSAdam Balogh std::forward_list<int> &FL2) {
430eb90692dSAdam Balogh auto i0 = FL1.cbegin(), i1 = FL2.cbegin(), i2 = FL2.cend();
431eb90692dSAdam Balogh
432eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL2), "$FL2.begin()");
433eb90692dSAdam Balogh
434eb90692dSAdam Balogh FL1 = std::move(FL2);
435eb90692dSAdam Balogh
436eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
437eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
438eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}} FIXME: Should be FALSE.
439eb90692dSAdam Balogh
440eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i1) == &FL1); // expected-warning{{TRUE}}
441eb90692dSAdam Balogh
442ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL2.begin(){{$}}}}
443eb90692dSAdam Balogh }
444eb90692dSAdam Balogh
445eb90692dSAdam Balogh
446eb90692dSAdam Balogh ////////////////////////////////////////////////////////////////////////////////
447eb90692dSAdam Balogh ///
448eb90692dSAdam Balogh /// C O N T A I N E R M O D I F I E R S
449eb90692dSAdam Balogh ///
450eb90692dSAdam Balogh ////////////////////////////////////////////////////////////////////////////////
451eb90692dSAdam Balogh
452eb90692dSAdam Balogh /// assign()
453eb90692dSAdam Balogh ///
454eb90692dSAdam Balogh /// - Invalidates all iterators, including the past-the-end iterator for all
455eb90692dSAdam Balogh /// container types.
456eb90692dSAdam Balogh
list_assign(std::list<int> & L,int n)457eb90692dSAdam Balogh void list_assign(std::list<int> &L, int n) {
458eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = L.cend();
459eb90692dSAdam Balogh L.assign(10, n);
460eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
461eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
462eb90692dSAdam Balogh }
463eb90692dSAdam Balogh
vector_assign(std::vector<int> & V,int n)464eb90692dSAdam Balogh void vector_assign(std::vector<int> &V, int n) {
465eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = V.cend();
466eb90692dSAdam Balogh V.assign(10, n);
467eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
468eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
469eb90692dSAdam Balogh }
470eb90692dSAdam Balogh
deque_assign(std::deque<int> & D,int n)471eb90692dSAdam Balogh void deque_assign(std::deque<int> &D, int n) {
472eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = D.cend();
473eb90692dSAdam Balogh D.assign(10, n);
474eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
475eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
476eb90692dSAdam Balogh }
477eb90692dSAdam Balogh
forward_list_assign(std::forward_list<int> & FL,int n)478eb90692dSAdam Balogh void forward_list_assign(std::forward_list<int> &FL, int n) {
479eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = FL.cend();
480eb90692dSAdam Balogh FL.assign(10, n);
481eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
482eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
483eb90692dSAdam Balogh }
484eb90692dSAdam Balogh
485eb90692dSAdam Balogh /// clear()
486eb90692dSAdam Balogh ///
487eb90692dSAdam Balogh /// - Invalidates all iterators, including the past-the-end iterator for all
488eb90692dSAdam Balogh /// container types.
489eb90692dSAdam Balogh
list_clear(std::list<int> & L)490eb90692dSAdam Balogh void list_clear(std::list<int> &L) {
491eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = L.cend();
492eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
493eb90692dSAdam Balogh L.clear();
494eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
495eb90692dSAdam Balogh }
496eb90692dSAdam Balogh
vector_clear(std::vector<int> & V)497eb90692dSAdam Balogh void vector_clear(std::vector<int> &V) {
498eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = V.cend();
499eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
500eb90692dSAdam Balogh V.clear();
501eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
502eb90692dSAdam Balogh }
503eb90692dSAdam Balogh
deque_clear(std::deque<int> & D)504eb90692dSAdam Balogh void deque_clear(std::deque<int> &D) {
505eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = D.cend();
506eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
507eb90692dSAdam Balogh D.clear();
508eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
509eb90692dSAdam Balogh }
510eb90692dSAdam Balogh
forward_list_clear(std::forward_list<int> & FL)511eb90692dSAdam Balogh void forward_list_clear(std::forward_list<int> &FL) {
512eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = FL.cend();
513eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
514eb90692dSAdam Balogh FL.clear();
515eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
516eb90692dSAdam Balogh }
517eb90692dSAdam Balogh
518eb90692dSAdam Balogh /// push_back()
519eb90692dSAdam Balogh ///
520eb90692dSAdam Balogh /// - Design decision: extends containers to the ->RIGHT-> (i.e. the
521eb90692dSAdam Balogh /// past-the-end position of the container is incremented).
522eb90692dSAdam Balogh ///
523eb90692dSAdam Balogh /// - Iterator invalidation rules depend the container type.
524eb90692dSAdam Balogh
525eb90692dSAdam Balogh /// std::list-like containers: No iterators are invalidated.
526eb90692dSAdam Balogh
list_push_back(std::list<int> & L,int n)527eb90692dSAdam Balogh void list_push_back(std::list<int> &L, int n) {
528eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
529eb90692dSAdam Balogh
530eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
531eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
532eb90692dSAdam Balogh
533eb90692dSAdam Balogh L.push_back(n);
534eb90692dSAdam Balogh
535eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
536eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
537eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
538eb90692dSAdam Balogh
539ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
540ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}}
541ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}} FIXME: Should be $L.end() + 1
542eb90692dSAdam Balogh }
543eb90692dSAdam Balogh
544eb90692dSAdam Balogh /// std::vector-like containers: The past-the-end iterator is invalidated.
545eb90692dSAdam Balogh
vector_push_back(std::vector<int> & V,int n)546eb90692dSAdam Balogh void vector_push_back(std::vector<int> &V, int n) {
547eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
548eb90692dSAdam Balogh
549eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
550eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
551eb90692dSAdam Balogh
552eb90692dSAdam Balogh V.push_back(n);
553eb90692dSAdam Balogh
554eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
555eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
556eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
557eb90692dSAdam Balogh
558ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
559ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V.end() - 1{{$}}}}
560eb90692dSAdam Balogh }
561eb90692dSAdam Balogh
562eb90692dSAdam Balogh /// std::deque-like containers: All iterators, including the past-the-end
563eb90692dSAdam Balogh /// iterator, are invalidated.
564eb90692dSAdam Balogh
deque_push_back(std::deque<int> & D,int n)565eb90692dSAdam Balogh void deque_push_back(std::deque<int> &D, int n) {
566eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
567eb90692dSAdam Balogh
568eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
569eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
570eb90692dSAdam Balogh
571eb90692dSAdam Balogh D.push_back(n);
572eb90692dSAdam Balogh
573eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
574eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
575eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
576eb90692dSAdam Balogh }
577eb90692dSAdam Balogh
578eb90692dSAdam Balogh /// emplace_back()
579eb90692dSAdam Balogh ///
580eb90692dSAdam Balogh /// - Design decision: extends containers to the ->RIGHT-> (i.e. the
581eb90692dSAdam Balogh /// past-the-end position of the container is incremented).
582eb90692dSAdam Balogh ///
583eb90692dSAdam Balogh /// - Iterator invalidation rules depend the container type.
584eb90692dSAdam Balogh
585eb90692dSAdam Balogh /// std::list-like containers: No iterators are invalidated.
586eb90692dSAdam Balogh
list_emplace_back(std::list<int> & L,int n)587eb90692dSAdam Balogh void list_emplace_back(std::list<int> &L, int n) {
588eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
589eb90692dSAdam Balogh
590eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
591eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
592eb90692dSAdam Balogh
593eb90692dSAdam Balogh L.emplace_back(n);
594eb90692dSAdam Balogh
595eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
596eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
597eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
598eb90692dSAdam Balogh
599ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
600ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}}
601ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}} FIXME: Should be $L.end() + 1
602eb90692dSAdam Balogh }
603eb90692dSAdam Balogh
604eb90692dSAdam Balogh /// std::vector-like containers: The past-the-end iterator is invalidated.
605eb90692dSAdam Balogh
vector_emplace_back(std::vector<int> & V,int n)606eb90692dSAdam Balogh void vector_emplace_back(std::vector<int> &V, int n) {
607eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
608eb90692dSAdam Balogh
609eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
610eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
611eb90692dSAdam Balogh
612eb90692dSAdam Balogh V.emplace_back(n);
613eb90692dSAdam Balogh
614eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
615eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
616eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
617eb90692dSAdam Balogh
618ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
619ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V.end() - 1{{$}}}}
620eb90692dSAdam Balogh }
621eb90692dSAdam Balogh
622eb90692dSAdam Balogh /// std::deque-like containers: All iterators, including the past-the-end
623eb90692dSAdam Balogh /// iterator, are invalidated.
624eb90692dSAdam Balogh
deque_emplace_back(std::deque<int> & D,int n)625eb90692dSAdam Balogh void deque_emplace_back(std::deque<int> &D, int n) {
626eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
627eb90692dSAdam Balogh
628eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
629eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
630eb90692dSAdam Balogh
631eb90692dSAdam Balogh D.emplace_back(n);
632eb90692dSAdam Balogh
633eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
634eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
635eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
636eb90692dSAdam Balogh }
637eb90692dSAdam Balogh
638eb90692dSAdam Balogh /// pop_back()
639eb90692dSAdam Balogh ///
640eb90692dSAdam Balogh /// - Design decision: shrinks containers to the <-LEFT<- (i.e. the
641eb90692dSAdam Balogh /// past-the-end position of the container is decremented).
642eb90692dSAdam Balogh ///
643eb90692dSAdam Balogh /// - Iterator invalidation rules depend the container type.
644eb90692dSAdam Balogh
645eb90692dSAdam Balogh /// std::list-like containers: Iterators to the last element are invalidated.
646eb90692dSAdam Balogh
list_pop_back(std::list<int> & L,int n)647eb90692dSAdam Balogh void list_pop_back(std::list<int> &L, int n) {
648eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
649eb90692dSAdam Balogh
650eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
651eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
652eb90692dSAdam Balogh
653eb90692dSAdam Balogh L.pop_back();
654eb90692dSAdam Balogh
655eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
656eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
657eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
658eb90692dSAdam Balogh
659ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
660ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}} FIXME: Should be $L.end() - 1
661eb90692dSAdam Balogh }
662eb90692dSAdam Balogh
663eb90692dSAdam Balogh /// std::vector-like containers: Iterators to the last element, as well as the
664eb90692dSAdam Balogh /// past-the-end iterator, are invalidated.
665eb90692dSAdam Balogh
vector_pop_back(std::vector<int> & V,int n)666eb90692dSAdam Balogh void vector_pop_back(std::vector<int> &V, int n) {
667eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
668eb90692dSAdam Balogh
669eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
670eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
671eb90692dSAdam Balogh
672eb90692dSAdam Balogh V.pop_back();
673eb90692dSAdam Balogh
674eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
675eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
676eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
677eb90692dSAdam Balogh
678ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
679eb90692dSAdam Balogh }
680eb90692dSAdam Balogh
681eb90692dSAdam Balogh /// std::deque-like containers: Iterators to the last element are invalidated.
682eb90692dSAdam Balogh /// The past-the-end iterator is also invalidated.
683eb90692dSAdam Balogh /// Other iterators are not affected.
684eb90692dSAdam Balogh
deque_pop_back(std::deque<int> & D,int n)685eb90692dSAdam Balogh void deque_pop_back(std::deque<int> &D, int n) {
686eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
687eb90692dSAdam Balogh
688eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
689eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
690eb90692dSAdam Balogh
691eb90692dSAdam Balogh D.pop_back();
692eb90692dSAdam Balogh
693eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
694eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
695eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
696eb90692dSAdam Balogh
697ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$D.begin(){{$}}}}
698eb90692dSAdam Balogh }
699eb90692dSAdam Balogh
700eb90692dSAdam Balogh /// push_front()
701eb90692dSAdam Balogh ///
702eb90692dSAdam Balogh /// - Design decision: extends containers to the <-LEFT<- (i.e. the first
703eb90692dSAdam Balogh /// position of the container is decremented).
704eb90692dSAdam Balogh ///
705eb90692dSAdam Balogh /// - Iterator invalidation rules depend the container type.
706eb90692dSAdam Balogh
707eb90692dSAdam Balogh /// std::list-like containers: No iterators are invalidated.
708eb90692dSAdam Balogh
list_push_front(std::list<int> & L,int n)709eb90692dSAdam Balogh void list_push_front(std::list<int> &L, int n) {
710eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = L.cend();
711eb90692dSAdam Balogh
712eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
713eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
714eb90692dSAdam Balogh
715eb90692dSAdam Balogh L.push_front(n);
716eb90692dSAdam Balogh
717eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
718eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
719eb90692dSAdam Balogh
720ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
721ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end(){{$}}}}
722eb90692dSAdam Balogh }
723eb90692dSAdam Balogh
724eb90692dSAdam Balogh /// std::deque-like containers: All iterators, including the past-the-end
725eb90692dSAdam Balogh /// iterator, are invalidated.
726eb90692dSAdam Balogh
deque_push_front(std::deque<int> & D,int n)727eb90692dSAdam Balogh void deque_push_front(std::deque<int> &D, int n) {
728eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
729eb90692dSAdam Balogh
730eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
731eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
732eb90692dSAdam Balogh
733eb90692dSAdam Balogh D.push_front(n);
734eb90692dSAdam Balogh
735eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
736eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
737eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
738eb90692dSAdam Balogh }
739eb90692dSAdam Balogh
740eb90692dSAdam Balogh /// std::forward_list-like containers: No iterators are invalidated.
741eb90692dSAdam Balogh
forward_list_push_front(std::forward_list<int> & FL,int n)742eb90692dSAdam Balogh void forward_list_push_front(std::forward_list<int> &FL, int n) {
743eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = FL.cend();
744eb90692dSAdam Balogh
745eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
746eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
747eb90692dSAdam Balogh
748eb90692dSAdam Balogh FL.push_front(n);
749eb90692dSAdam Balogh
750eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
751eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
752eb90692dSAdam Balogh
753ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
754ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.end(){{$}}}}
755eb90692dSAdam Balogh }
756eb90692dSAdam Balogh
757eb90692dSAdam Balogh /// emplace_front()
758eb90692dSAdam Balogh ///
759eb90692dSAdam Balogh /// - Design decision: extends containers to the <-LEFT<- (i.e. the first
760eb90692dSAdam Balogh /// position of the container is decremented).
761eb90692dSAdam Balogh ///
762eb90692dSAdam Balogh /// - Iterator invalidation rules depend the container type.
763eb90692dSAdam Balogh
764eb90692dSAdam Balogh /// std::list-like containers: No iterators are invalidated.
765eb90692dSAdam Balogh
list_emplace_front(std::list<int> & L,int n)766eb90692dSAdam Balogh void list_emplace_front(std::list<int> &L, int n) {
767eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = L.cend();
768eb90692dSAdam Balogh
769eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
770eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
771eb90692dSAdam Balogh
772eb90692dSAdam Balogh L.emplace_front(n);
773eb90692dSAdam Balogh
774eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
775eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
776eb90692dSAdam Balogh
777ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
778ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end(){{$}}}}
779eb90692dSAdam Balogh }
780eb90692dSAdam Balogh
781eb90692dSAdam Balogh /// std::deque-like containers: All iterators, including the past-the-end
782eb90692dSAdam Balogh /// iterator, are invalidated.
783eb90692dSAdam Balogh
deque_emplace_front(std::deque<int> & D,int n)784eb90692dSAdam Balogh void deque_emplace_front(std::deque<int> &D, int n) {
785eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
786eb90692dSAdam Balogh
787eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
788eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
789eb90692dSAdam Balogh
790eb90692dSAdam Balogh D.emplace_front(n);
791eb90692dSAdam Balogh
792eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
793eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
794eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
795eb90692dSAdam Balogh }
796eb90692dSAdam Balogh
797eb90692dSAdam Balogh /// std::forward_list-like containers: No iterators are invalidated.
798eb90692dSAdam Balogh
forward_list_emplace_front(std::forward_list<int> & FL,int n)799eb90692dSAdam Balogh void forward_list_emplace_front(std::forward_list<int> &FL, int n) {
800eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = FL.cend();
801eb90692dSAdam Balogh
802eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
803eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
804eb90692dSAdam Balogh
805eb90692dSAdam Balogh FL.emplace_front(n);
806eb90692dSAdam Balogh
807eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
808eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
809eb90692dSAdam Balogh
810ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
811ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.end(){{$}}}}
812eb90692dSAdam Balogh }
813eb90692dSAdam Balogh
814eb90692dSAdam Balogh /// pop_front()
815eb90692dSAdam Balogh ///
816eb90692dSAdam Balogh /// - Design decision: shrinks containers to the ->RIGHT-> (i.e. the first
817eb90692dSAdam Balogh /// position of the container is incremented).
818eb90692dSAdam Balogh ///
819eb90692dSAdam Balogh /// - Iterator invalidation rules depend the container type.
820eb90692dSAdam Balogh
821eb90692dSAdam Balogh /// std::list-like containers: Iterators to the first element are invalidated.
822eb90692dSAdam Balogh
list_pop_front(std::list<int> & L,int n)823eb90692dSAdam Balogh void list_pop_front(std::list<int> &L, int n) {
824eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend();
825eb90692dSAdam Balogh
826eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
827eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
828eb90692dSAdam Balogh
829eb90692dSAdam Balogh L.pop_front();
830eb90692dSAdam Balogh
831eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
832eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
833eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
834eb90692dSAdam Balogh
835ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.begin() + 1{{$}}}}
836ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
837eb90692dSAdam Balogh }
838eb90692dSAdam Balogh
839eb90692dSAdam Balogh /// std::deque-like containers: Iterators to the first element are invalidated.
840eb90692dSAdam Balogh /// Other iterators are not affected.
841eb90692dSAdam Balogh
deque_pop_front(std::deque<int> & D,int n)842eb90692dSAdam Balogh void deque_pop_front(std::deque<int> &D, int n) {
843eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = ++D.cbegin(), i2 = D.cend();
844eb90692dSAdam Balogh
845eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
846eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
847eb90692dSAdam Balogh
848eb90692dSAdam Balogh D.pop_front();
849eb90692dSAdam Balogh
850eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
851eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
852eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
853eb90692dSAdam Balogh
854ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$D.begin() + 1{{$}}}}
855ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$D.end(){{$}}}}
856eb90692dSAdam Balogh }
857eb90692dSAdam Balogh
858eb90692dSAdam Balogh /// std::forward_list-like containers: Iterators to the first element are
859eb90692dSAdam Balogh /// invalidated.
860eb90692dSAdam Balogh
forward_list_pop_front(std::list<int> & FL,int n)861eb90692dSAdam Balogh void forward_list_pop_front(std::list<int> &FL, int n) {
862eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = ++FL.cbegin(), i2 = FL.cend();
863eb90692dSAdam Balogh
864eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
865eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
866eb90692dSAdam Balogh
867eb90692dSAdam Balogh FL.pop_front();
868eb90692dSAdam Balogh
869eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
870eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
871eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
872eb90692dSAdam Balogh
873ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.begin() + 1{{$}}}}
874ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.end(){{$}}}}
875eb90692dSAdam Balogh }
876eb90692dSAdam Balogh
877eb90692dSAdam Balogh /// insert()
878eb90692dSAdam Balogh ///
879eb90692dSAdam Balogh /// - Design decision: shifts positions to the <-LEFT<- (i.e. all iterator
880eb90692dSAdam Balogh /// ahead of the insertion point are decremented; if the
881eb90692dSAdam Balogh /// relation between the insertion point and the first
882eb90692dSAdam Balogh /// position of the container is known, the first position
883eb90692dSAdam Balogh /// of the container is also decremented).
884eb90692dSAdam Balogh ///
885eb90692dSAdam Balogh /// - Iterator invalidation rules depend the container type.
886eb90692dSAdam Balogh
887eb90692dSAdam Balogh /// std::list-like containers: No iterators are invalidated.
888eb90692dSAdam Balogh
list_insert_begin(std::list<int> & L,int n)889eb90692dSAdam Balogh void list_insert_begin(std::list<int> &L, int n) {
890eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = L.cend();
891eb90692dSAdam Balogh
892eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
893eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
894eb90692dSAdam Balogh
895eb90692dSAdam Balogh auto i2 = L.insert(i0, n);
896eb90692dSAdam Balogh
897eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
898eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
899eb90692dSAdam Balogh
900ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
901eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $L.begin() - 1
902ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end(){{$}}}}
903eb90692dSAdam Balogh }
904eb90692dSAdam Balogh
list_insert_behind_begin(std::list<int> & L,int n)905eb90692dSAdam Balogh void list_insert_behind_begin(std::list<int> &L, int n) {
906eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend();
907eb90692dSAdam Balogh
908eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
909eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
910eb90692dSAdam Balogh
911eb90692dSAdam Balogh auto i3 = L.insert(i1, n);
912eb90692dSAdam Balogh
913eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
914eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
915eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
916eb90692dSAdam Balogh
917ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}} FIXME: Should be $L.begin() - 1
918ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.begin() + 1{{$}}}}
919eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.begin()
920ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
921eb90692dSAdam Balogh }
922eb90692dSAdam Balogh
923eb90692dSAdam Balogh template <typename Iter> Iter return_any_iterator(const Iter &It);
924eb90692dSAdam Balogh
list_insert_unknown(std::list<int> & L,int n)925eb90692dSAdam Balogh void list_insert_unknown(std::list<int> &L, int n) {
926eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = return_any_iterator(L.cbegin()), i2 = L.cend();
927eb90692dSAdam Balogh
928eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
929eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
930eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
931eb90692dSAdam Balogh
932eb90692dSAdam Balogh auto i3 = L.insert(i1, n);
933eb90692dSAdam Balogh
934eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
935eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
936eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
937eb90692dSAdam Balogh
938ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
939ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$i1{{$}}}}
940eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i - 1
941ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
942eb90692dSAdam Balogh }
943eb90692dSAdam Balogh
list_insert_ahead_of_end(std::list<int> & L,int n)944eb90692dSAdam Balogh void list_insert_ahead_of_end(std::list<int> &L, int n) {
945eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
946eb90692dSAdam Balogh
947eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
948eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
949eb90692dSAdam Balogh
950eb90692dSAdam Balogh auto i3 = L.insert(i1, n);
951eb90692dSAdam Balogh
952eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
953eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
954eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
955eb90692dSAdam Balogh
956ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
957ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}}
958ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
959eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end() - 2
960eb90692dSAdam Balogh }
961eb90692dSAdam Balogh
list_insert_end(std::list<int> & L,int n)962eb90692dSAdam Balogh void list_insert_end(std::list<int> &L, int n) {
963eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
964eb90692dSAdam Balogh
965eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
966eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
967eb90692dSAdam Balogh
968eb90692dSAdam Balogh auto i3 = L.insert(i2, n);
969eb90692dSAdam Balogh
970eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
971eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
972eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
973eb90692dSAdam Balogh
974ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
975ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}} FIXME: should be $L.end() - 2
976ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
977eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end() - 1
978eb90692dSAdam Balogh }
979eb90692dSAdam Balogh
980eb90692dSAdam Balogh /// std::vector-like containers: Only the iterators before the insertion point
981eb90692dSAdam Balogh /// remain valid. The past-the-end iterator is also
982eb90692dSAdam Balogh /// invalidated.
983eb90692dSAdam Balogh
vector_insert_begin(std::vector<int> & V,int n)984eb90692dSAdam Balogh void vector_insert_begin(std::vector<int> &V, int n) {
985eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = V.cend();
986eb90692dSAdam Balogh
987eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
988eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
989eb90692dSAdam Balogh
990eb90692dSAdam Balogh auto i2 = V.insert(i0, n);
991eb90692dSAdam Balogh
992eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
993eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
994eb90692dSAdam Balogh
995eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $V.begin() - 1
996eb90692dSAdam Balogh }
997eb90692dSAdam Balogh
vector_insert_behind_begin(std::vector<int> & V,int n)998eb90692dSAdam Balogh void vector_insert_behind_begin(std::vector<int> &V, int n) {
999eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = ++V.cbegin(), i2 = V.cend();
1000eb90692dSAdam Balogh
1001eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1002eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1003eb90692dSAdam Balogh
1004eb90692dSAdam Balogh auto i3 = V.insert(i1, n);
1005eb90692dSAdam Balogh
1006eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1007eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1008eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1009eb90692dSAdam Balogh
1010ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}} FIXME: Should be $V.begin() - 1
1011eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); // FIXME: expect -warning $V.begin()
1012eb90692dSAdam Balogh }
1013eb90692dSAdam Balogh
vector_insert_unknown(std::vector<int> & V,int n)1014eb90692dSAdam Balogh void vector_insert_unknown(std::vector<int> &V, int n) {
1015eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = return_any_iterator(V.cbegin()), i2 = V.cend();
1016eb90692dSAdam Balogh
1017eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1018eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1019eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1020eb90692dSAdam Balogh
1021eb90692dSAdam Balogh auto i3 = V.insert(i1, n);
1022eb90692dSAdam Balogh
1023eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1024eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1025eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1026eb90692dSAdam Balogh
1027ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1028eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expecte warning $i1 - 1
1029eb90692dSAdam Balogh }
1030eb90692dSAdam Balogh
vector_insert_ahead_of_end(std::vector<int> & V,int n)1031eb90692dSAdam Balogh void vector_insert_ahead_of_end(std::vector<int> &V, int n) {
1032eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
1033eb90692dSAdam Balogh
1034eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1035eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1036eb90692dSAdam Balogh
1037eb90692dSAdam Balogh auto i3 = V.insert(i1, n);
1038eb90692dSAdam Balogh
1039eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1040eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1041eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1042eb90692dSAdam Balogh
1043ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1044eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.end() - 2
1045eb90692dSAdam Balogh }
1046eb90692dSAdam Balogh
vector_insert_end(std::vector<int> & V,int n)1047eb90692dSAdam Balogh void vector_insert_end(std::vector<int> &V, int n) {
1048eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
1049eb90692dSAdam Balogh
1050eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1051eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1052eb90692dSAdam Balogh
1053eb90692dSAdam Balogh auto i3 = V.insert(i2, n);
1054eb90692dSAdam Balogh
1055eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1056eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1057eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1058eb90692dSAdam Balogh
1059ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1060ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V.end() - 1{{$}}}} FIXME: Should be $V.end() - 2
1061eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.end() - 1
1062eb90692dSAdam Balogh }
1063eb90692dSAdam Balogh
1064eb90692dSAdam Balogh /// std::deque-like containers: All iterators, including the past-the-end
1065eb90692dSAdam Balogh /// iterator, are invalidated.
1066eb90692dSAdam Balogh
deque_insert_begin(std::deque<int> & D,int n)1067eb90692dSAdam Balogh void deque_insert_begin(std::deque<int> &D, int n) {
1068eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = D.cend();
1069eb90692dSAdam Balogh
1070eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1071eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1072eb90692dSAdam Balogh
1073eb90692dSAdam Balogh auto i2 = D.insert(i0, n);
1074eb90692dSAdam Balogh
1075eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1076eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1077eb90692dSAdam Balogh
1078eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $D.begin() - 1
1079eb90692dSAdam Balogh }
1080eb90692dSAdam Balogh
deque_insert_behind_begin(std::deque<int> & D,int n)1081eb90692dSAdam Balogh void deque_insert_behind_begin(std::deque<int> &D, int n) {
1082eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = ++D.cbegin(), i2 = D.cend();
1083eb90692dSAdam Balogh
1084eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1085eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1086eb90692dSAdam Balogh
1087eb90692dSAdam Balogh auto i3 = D.insert(i1, n);
1088eb90692dSAdam Balogh
1089eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1090eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1091eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1092eb90692dSAdam Balogh
1093eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.begin() - 1
1094eb90692dSAdam Balogh }
1095eb90692dSAdam Balogh
deque_insert_unknown(std::deque<int> & D,int n)1096eb90692dSAdam Balogh void deque_insert_unknown(std::deque<int> &D, int n) {
1097eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = return_any_iterator(D.cbegin()), i2 = D.cend();
1098eb90692dSAdam Balogh
1099eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1100eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1101eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1102eb90692dSAdam Balogh
1103eb90692dSAdam Balogh auto i3 = D.insert(i1, n);
1104eb90692dSAdam Balogh
1105eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1106eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1107eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1108eb90692dSAdam Balogh
1109eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 - 1
1110eb90692dSAdam Balogh }
1111eb90692dSAdam Balogh
deque_insert_ahead_of_end(std::deque<int> & D,int n)1112eb90692dSAdam Balogh void deque_insert_ahead_of_end(std::deque<int> &D, int n) {
1113eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
1114eb90692dSAdam Balogh
1115eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1116eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1117eb90692dSAdam Balogh
1118eb90692dSAdam Balogh auto i3 = D.insert(i1, n);
1119eb90692dSAdam Balogh
1120eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1121eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1122eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1123eb90692dSAdam Balogh
1124eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 2
1125eb90692dSAdam Balogh }
1126eb90692dSAdam Balogh
deque_insert_end(std::deque<int> & D,int n)1127eb90692dSAdam Balogh void deque_insert_end(std::deque<int> &D, int n) {
1128eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
1129eb90692dSAdam Balogh
1130eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1131eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1132eb90692dSAdam Balogh
1133eb90692dSAdam Balogh auto i3 = D.insert(i2, n);
1134eb90692dSAdam Balogh
1135eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1136eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1137eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1138eb90692dSAdam Balogh
1139eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 1
1140eb90692dSAdam Balogh }
1141eb90692dSAdam Balogh
1142eb90692dSAdam Balogh /// insert_after() [std::forward_list-like containers]
1143eb90692dSAdam Balogh ///
1144eb90692dSAdam Balogh /// - Design decision: shifts positions to the ->RIGHT-> (i.e. all iterator
1145eb90692dSAdam Balogh /// ahead of the insertion point are incremented; if the
1146eb90692dSAdam Balogh /// relation between the insertion point and the past-the-end
1147eb90692dSAdam Balogh /// position of the container is known, the first position of
1148eb90692dSAdam Balogh /// the container is also incremented).
1149eb90692dSAdam Balogh ///
1150eb90692dSAdam Balogh /// - No iterators are invalidated.
1151eb90692dSAdam Balogh
forward_list_insert_after_begin(std::forward_list<int> & FL,int n)1152eb90692dSAdam Balogh void forward_list_insert_after_begin(std::forward_list<int> &FL, int n) {
1153eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = FL.cend();
1154eb90692dSAdam Balogh
1155eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1156eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1157eb90692dSAdam Balogh
1158eb90692dSAdam Balogh auto i2 = FL.insert_after(i0, n);
1159eb90692dSAdam Balogh
1160eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1161eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1162eb90692dSAdam Balogh
1163ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1164eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $FL.begin() + 1
1165ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.end(){{$}}}}
1166eb90692dSAdam Balogh }
1167eb90692dSAdam Balogh
forward_list_insert_after_behind_begin(std::forward_list<int> & FL,int n)1168eb90692dSAdam Balogh void forward_list_insert_after_behind_begin(std::forward_list<int> &FL, int n) {
1169eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = ++FL.cbegin(), i2 = FL.cend();
1170eb90692dSAdam Balogh
1171eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1172eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1173eb90692dSAdam Balogh
1174eb90692dSAdam Balogh auto i3 = FL.insert_after(i1, n);
1175eb90692dSAdam Balogh
1176eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1177eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1178eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1179eb90692dSAdam Balogh
1180ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1181ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.begin() + 1{{$}}}}
1182eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $FL.begin() + 2
1183ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.end(){{$}}}}
1184eb90692dSAdam Balogh }
1185eb90692dSAdam Balogh
forward_list_insert_after_unknown(std::forward_list<int> & FL,int n)1186eb90692dSAdam Balogh void forward_list_insert_after_unknown(std::forward_list<int> &FL, int n) {
1187eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = return_any_iterator(FL.cbegin()), i2 = FL.cend();
1188eb90692dSAdam Balogh
1189eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1190eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1191eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1192eb90692dSAdam Balogh
1193eb90692dSAdam Balogh auto i3 = FL.insert_after(i1, n);
1194eb90692dSAdam Balogh
1195eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1196eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1197eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1198eb90692dSAdam Balogh
1199ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1200ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$i1{{$}}}}
1201eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 + 1
1202ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.end(){{$}}}}
1203eb90692dSAdam Balogh }
1204eb90692dSAdam Balogh
1205eb90692dSAdam Balogh /// emplace()
1206eb90692dSAdam Balogh ///
1207eb90692dSAdam Balogh /// - Design decision: shifts positions to the <-LEFT<- (i.e. all iterator
1208eb90692dSAdam Balogh /// ahead of the emplacement point are decremented; if the
1209eb90692dSAdam Balogh /// relation between the emplacement point and the first
1210eb90692dSAdam Balogh /// position of the container is known, the first position
1211eb90692dSAdam Balogh /// of the container is also decremented).
1212eb90692dSAdam Balogh ///
1213eb90692dSAdam Balogh /// - Iterator invalidation rules depend the container type.
1214eb90692dSAdam Balogh
1215eb90692dSAdam Balogh /// std::list-like containers: No iterators are invalidated.
1216eb90692dSAdam Balogh
list_emplace_begin(std::list<int> & L,int n)1217eb90692dSAdam Balogh void list_emplace_begin(std::list<int> &L, int n) {
1218eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = L.cend();
1219eb90692dSAdam Balogh
1220eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1221eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1222eb90692dSAdam Balogh
1223eb90692dSAdam Balogh auto i2 = L.emplace(i0, n);
1224eb90692dSAdam Balogh
1225eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1226eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1227eb90692dSAdam Balogh
1228ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1229eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $L.begin() - 1
1230ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end(){{$}}}}
1231eb90692dSAdam Balogh }
1232eb90692dSAdam Balogh
list_emplace_behind_begin(std::list<int> & L,int n)1233eb90692dSAdam Balogh void list_emplace_behind_begin(std::list<int> &L, int n) {
1234eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend();
1235eb90692dSAdam Balogh
1236eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1237eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1238eb90692dSAdam Balogh
1239eb90692dSAdam Balogh auto i3 = L.emplace(i1, n);
1240eb90692dSAdam Balogh
1241eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1242eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1243eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1244eb90692dSAdam Balogh
1245ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}} FIXME: Should be $L.begin() - 1
1246ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.begin() + 1{{$}}}}
1247eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.begin()
1248ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1249eb90692dSAdam Balogh }
1250eb90692dSAdam Balogh
1251eb90692dSAdam Balogh template <typename Iter> Iter return_any_iterator(const Iter &It);
1252eb90692dSAdam Balogh
list_emplace_unknown(std::list<int> & L,int n)1253eb90692dSAdam Balogh void list_emplace_unknown(std::list<int> &L, int n) {
1254eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = return_any_iterator(L.cbegin()), i2 = L.cend();
1255eb90692dSAdam Balogh
1256eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1257eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1258eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1259eb90692dSAdam Balogh
1260eb90692dSAdam Balogh auto i3 = L.emplace(i1, n);
1261eb90692dSAdam Balogh
1262eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1263eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1264eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1265eb90692dSAdam Balogh
1266ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1267ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$i1{{$}}}}
1268eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i - 1
1269ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1270eb90692dSAdam Balogh }
1271eb90692dSAdam Balogh
list_emplace_ahead_of_end(std::list<int> & L,int n)1272eb90692dSAdam Balogh void list_emplace_ahead_of_end(std::list<int> &L, int n) {
1273eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
1274eb90692dSAdam Balogh
1275eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1276eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1277eb90692dSAdam Balogh
1278eb90692dSAdam Balogh auto i3 = L.emplace(i1, n);
1279eb90692dSAdam Balogh
1280eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1281eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1282eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1283eb90692dSAdam Balogh
1284ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1285ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}}
1286ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1287eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end() - 2
1288eb90692dSAdam Balogh }
1289eb90692dSAdam Balogh
list_emplace_end(std::list<int> & L,int n)1290eb90692dSAdam Balogh void list_emplace_end(std::list<int> &L, int n) {
1291eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
1292eb90692dSAdam Balogh
1293eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1294eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1295eb90692dSAdam Balogh
1296eb90692dSAdam Balogh auto i3 = L.emplace(i2, n);
1297eb90692dSAdam Balogh
1298eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1299eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1300eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1301eb90692dSAdam Balogh
1302ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1303ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}} FIXME: should be $L.end() - 2
1304ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1305eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end() - 1
1306eb90692dSAdam Balogh }
1307eb90692dSAdam Balogh
1308eb90692dSAdam Balogh /// std::vector-like containers: Only the iterators before the emplacement point
1309eb90692dSAdam Balogh /// remain valid. The past-the-end iterator is also
1310eb90692dSAdam Balogh /// invalidated.
1311eb90692dSAdam Balogh
vector_emplace_begin(std::vector<int> & V,int n)1312eb90692dSAdam Balogh void vector_emplace_begin(std::vector<int> &V, int n) {
1313eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = V.cend();
1314eb90692dSAdam Balogh
1315eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1316eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1317eb90692dSAdam Balogh
1318eb90692dSAdam Balogh auto i2 = V.emplace(i0, n);
1319eb90692dSAdam Balogh
1320eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1321eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1322eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $V.begin() - 1
1323eb90692dSAdam Balogh }
1324eb90692dSAdam Balogh
vector_emplace_behind_begin(std::vector<int> & V,int n)1325eb90692dSAdam Balogh void vector_emplace_behind_begin(std::vector<int> &V, int n) {
1326eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = ++V.cbegin(), i2 = V.cend();
1327eb90692dSAdam Balogh
1328eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1329eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1330eb90692dSAdam Balogh
1331eb90692dSAdam Balogh auto i3 = V.emplace(i1, n);
1332eb90692dSAdam Balogh
1333eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1334eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1335eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1336eb90692dSAdam Balogh
1337ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}} FIXME: Should be $V.begin() - 1
1338eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); // FIXME: expect -warning $V.begin()
1339eb90692dSAdam Balogh }
1340eb90692dSAdam Balogh
vector_emplace_unknown(std::vector<int> & V,int n)1341eb90692dSAdam Balogh void vector_emplace_unknown(std::vector<int> &V, int n) {
1342eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = return_any_iterator(V.cbegin()), i2 = V.cend();
1343eb90692dSAdam Balogh
1344eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1345eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1346eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1347eb90692dSAdam Balogh
1348eb90692dSAdam Balogh auto i3 = V.emplace(i1, n);
1349eb90692dSAdam Balogh
1350eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1351eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1352eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1353eb90692dSAdam Balogh
1354ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1355eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expecte warning $i1 - 1
1356eb90692dSAdam Balogh }
1357eb90692dSAdam Balogh
vector_emplace_ahead_of_end(std::vector<int> & V,int n)1358eb90692dSAdam Balogh void vector_emplace_ahead_of_end(std::vector<int> &V, int n) {
1359eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
1360eb90692dSAdam Balogh
1361eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1362eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1363eb90692dSAdam Balogh
1364eb90692dSAdam Balogh auto i3 = V.emplace(i1, n);
1365eb90692dSAdam Balogh
1366eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1367eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1368eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1369eb90692dSAdam Balogh
1370ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1371eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.end() - 2
1372eb90692dSAdam Balogh }
1373eb90692dSAdam Balogh
vector_emplace_end(std::vector<int> & V,int n)1374eb90692dSAdam Balogh void vector_emplace_end(std::vector<int> &V, int n) {
1375eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
1376eb90692dSAdam Balogh
1377eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1378eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1379eb90692dSAdam Balogh
1380eb90692dSAdam Balogh auto i3 = V.emplace(i2, n);
1381eb90692dSAdam Balogh
1382eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1383eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1384eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1385eb90692dSAdam Balogh
1386ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1387ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V.end() - 1{{$}}}} FIXME: Should be $V.end() - 2
1388eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.end() - 1
1389eb90692dSAdam Balogh }
1390eb90692dSAdam Balogh
1391eb90692dSAdam Balogh /// std::deque-like containers: All iterators, including the past-the-end
1392eb90692dSAdam Balogh /// iterator, are invalidated.
1393eb90692dSAdam Balogh
deque_emplace_begin(std::deque<int> & D,int n)1394eb90692dSAdam Balogh void deque_emplace_begin(std::deque<int> &D, int n) {
1395eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = D.cend();
1396eb90692dSAdam Balogh
1397eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1398eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1399eb90692dSAdam Balogh
1400eb90692dSAdam Balogh auto i2 = D.emplace(i0, n);
1401eb90692dSAdam Balogh
1402eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1403eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1404eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $D.begin() - 1
1405eb90692dSAdam Balogh }
1406eb90692dSAdam Balogh
deque_emplace_behind_begin(std::deque<int> & D,int n)1407eb90692dSAdam Balogh void deque_emplace_behind_begin(std::deque<int> &D, int n) {
1408eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = ++D.cbegin(), i2 = D.cend();
1409eb90692dSAdam Balogh
1410eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1411eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1412eb90692dSAdam Balogh
1413eb90692dSAdam Balogh auto i3 = D.emplace(i1, n);
1414eb90692dSAdam Balogh
1415eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1416eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1417eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1418eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.begin() - 1
1419eb90692dSAdam Balogh }
1420eb90692dSAdam Balogh
deque_emplace_unknown(std::deque<int> & D,int n)1421eb90692dSAdam Balogh void deque_emplace_unknown(std::deque<int> &D, int n) {
1422eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = return_any_iterator(D.cbegin()), i2 = D.cend();
1423eb90692dSAdam Balogh
1424eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1425eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1426eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1427eb90692dSAdam Balogh
1428eb90692dSAdam Balogh auto i3 = D.emplace(i1, n);
1429eb90692dSAdam Balogh
1430eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1431eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1432eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1433eb90692dSAdam Balogh
1434eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 - 1
1435eb90692dSAdam Balogh }
1436eb90692dSAdam Balogh
deque_emplace_ahead_of_end(std::deque<int> & D,int n)1437eb90692dSAdam Balogh void deque_emplace_ahead_of_end(std::deque<int> &D, int n) {
1438eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
1439eb90692dSAdam Balogh
1440eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1441eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1442eb90692dSAdam Balogh
1443eb90692dSAdam Balogh auto i3 = D.emplace(i1, n);
1444eb90692dSAdam Balogh
1445eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1446eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1447eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1448eb90692dSAdam Balogh
1449eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 2
1450eb90692dSAdam Balogh }
1451eb90692dSAdam Balogh
deque_emplace_end(std::deque<int> & D,int n)1452eb90692dSAdam Balogh void deque_emplace_end(std::deque<int> &D, int n) {
1453eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
1454eb90692dSAdam Balogh
1455eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1456eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1457eb90692dSAdam Balogh
1458eb90692dSAdam Balogh auto i3 = D.emplace(i2, n);
1459eb90692dSAdam Balogh
1460eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1461eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1462eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1463eb90692dSAdam Balogh
1464eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 1
1465eb90692dSAdam Balogh }
1466eb90692dSAdam Balogh
1467eb90692dSAdam Balogh /// emplace_after() [std::forward_list-like containers]
1468eb90692dSAdam Balogh ///
1469eb90692dSAdam Balogh /// - Design decision: shifts positions to the ->RIGHT-> (i.e. all iterator
1470eb90692dSAdam Balogh /// ahead of the emplacement point are incremented; if the
1471eb90692dSAdam Balogh /// relation between the emplacement point and the
1472eb90692dSAdam Balogh /// past-the-end position of the container is known, the
1473eb90692dSAdam Balogh /// first position of the container is also incremented).
1474eb90692dSAdam Balogh ///
1475eb90692dSAdam Balogh /// - No iterators are invalidated.
1476eb90692dSAdam Balogh
forward_list_emplace_after_begin(std::forward_list<int> & FL,int n)1477eb90692dSAdam Balogh void forward_list_emplace_after_begin(std::forward_list<int> &FL, int n) {
1478eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = FL.cend();
1479eb90692dSAdam Balogh
1480eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1481eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1482eb90692dSAdam Balogh
1483eb90692dSAdam Balogh auto i2 = FL.emplace_after(i0, n);
1484eb90692dSAdam Balogh
1485eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1486eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1487eb90692dSAdam Balogh
1488ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1489eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $FL.begin() + 1
1490ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.end(){{$}}}}
1491eb90692dSAdam Balogh }
1492eb90692dSAdam Balogh
forward_list_emplace_after_behind_begin(std::forward_list<int> & FL,int n)1493eb90692dSAdam Balogh void forward_list_emplace_after_behind_begin(std::forward_list<int> &FL,
1494eb90692dSAdam Balogh int n) {
1495eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = ++FL.cbegin(), i2 = FL.cend();
1496eb90692dSAdam Balogh
1497eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1498eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1499eb90692dSAdam Balogh
1500eb90692dSAdam Balogh auto i3 = FL.emplace_after(i1, n);
1501eb90692dSAdam Balogh
1502eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1503eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1504eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1505eb90692dSAdam Balogh
1506ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1507ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.begin() + 1{{$}}}}
1508eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $FL.begin() + 2
1509ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.end(){{$}}}}
1510eb90692dSAdam Balogh }
1511eb90692dSAdam Balogh
forward_list_emplace_after_unknown(std::forward_list<int> & FL,int n)1512eb90692dSAdam Balogh void forward_list_emplace_after_unknown(std::forward_list<int> &FL, int n) {
1513eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = return_any_iterator(FL.cbegin()), i2 = FL.cend();
1514eb90692dSAdam Balogh
1515eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1516eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1517eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1518eb90692dSAdam Balogh
1519eb90692dSAdam Balogh auto i3 = FL.emplace_after(i1, n);
1520eb90692dSAdam Balogh
1521eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1522eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1523eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1524eb90692dSAdam Balogh
1525ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1526ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$i1{{$}}}}
1527eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 + 1
1528ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.end(){{$}}}}
1529eb90692dSAdam Balogh }
1530eb90692dSAdam Balogh
1531eb90692dSAdam Balogh /// erase()
1532eb90692dSAdam Balogh ///
1533eb90692dSAdam Balogh /// - Design decision: shifts positions to the ->RIGHT-> (i.e. all iterator
1534eb90692dSAdam Balogh /// ahead of the ereased element are incremented; if the
1535eb90692dSAdam Balogh /// relation between the position of the erased element
1536eb90692dSAdam Balogh /// and the first position of the container is known, the
1537eb90692dSAdam Balogh /// first position of the container is also incremented).
1538eb90692dSAdam Balogh ///
1539eb90692dSAdam Balogh /// - Iterator invalidation rules depend the container type.
1540eb90692dSAdam Balogh
1541eb90692dSAdam Balogh /// std::list-like containers: Iterators to the erased element are invalidated.
1542eb90692dSAdam Balogh /// Other iterators are not affected.
1543eb90692dSAdam Balogh
list_erase_begin(std::list<int> & L)1544eb90692dSAdam Balogh void list_erase_begin(std::list<int> &L) {
1545eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend();
1546eb90692dSAdam Balogh
1547eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1548eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1549eb90692dSAdam Balogh
1550eb90692dSAdam Balogh auto i3 = L.erase(i0);
1551eb90692dSAdam Balogh
1552eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1553eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1554eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1555eb90692dSAdam Balogh
1556ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.begin() + 1{{$}}}}
1557eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.begin() + 1
1558ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1559eb90692dSAdam Balogh }
1560eb90692dSAdam Balogh
list_erase_behind_begin(std::list<int> & L,int n)1561eb90692dSAdam Balogh void list_erase_behind_begin(std::list<int> &L, int n) {
1562eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend();
1563eb90692dSAdam Balogh
1564eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1565eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1566eb90692dSAdam Balogh
1567eb90692dSAdam Balogh auto i3 = L.erase(i1);
1568eb90692dSAdam Balogh
1569eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1570eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1571eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1572eb90692dSAdam Balogh
1573ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}} FIXME: Should be $L.begin() + 1
1574eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.begin() + 2
1575ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1576eb90692dSAdam Balogh }
1577eb90692dSAdam Balogh
list_erase_unknown(std::list<int> & L)1578eb90692dSAdam Balogh void list_erase_unknown(std::list<int> &L) {
1579eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = return_any_iterator(L.cbegin()), i2 = L.cend();
1580eb90692dSAdam Balogh
1581eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1582eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1583eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1584eb90692dSAdam Balogh
1585eb90692dSAdam Balogh auto i3 = L.erase(i1);
1586eb90692dSAdam Balogh
1587eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1588eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1589eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1590eb90692dSAdam Balogh
1591ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1592eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 + 1
1593ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1594eb90692dSAdam Balogh }
1595eb90692dSAdam Balogh
list_erase_ahead_of_end(std::list<int> & L)1596eb90692dSAdam Balogh void list_erase_ahead_of_end(std::list<int> &L) {
1597eb90692dSAdam Balogh auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
1598eb90692dSAdam Balogh
1599eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1600eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1601eb90692dSAdam Balogh
1602eb90692dSAdam Balogh auto i3 = L.erase(i1);
1603eb90692dSAdam Balogh
1604eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1605eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1606eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1607eb90692dSAdam Balogh
1608ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1609ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1610eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end()
1611eb90692dSAdam Balogh }
1612eb90692dSAdam Balogh
1613eb90692dSAdam Balogh /// std::vector-like containers: Invalidates iterators at or after the point of
1614eb90692dSAdam Balogh /// the erase, including the past-the-end iterator.
1615eb90692dSAdam Balogh
vector_erase_begin(std::vector<int> & V)1616eb90692dSAdam Balogh void vector_erase_begin(std::vector<int> &V) {
1617eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = ++V.cbegin(), i2 = V.cend();
1618eb90692dSAdam Balogh
1619eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1620eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1621eb90692dSAdam Balogh
1622eb90692dSAdam Balogh auto i3 = V.erase(i0);
1623eb90692dSAdam Balogh
1624eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1625eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1626eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1627eb90692dSAdam Balogh
1628eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.begin() + 1
1629eb90692dSAdam Balogh }
1630eb90692dSAdam Balogh
vector_erase_behind_begin(std::vector<int> & V,int n)1631eb90692dSAdam Balogh void vector_erase_behind_begin(std::vector<int> &V, int n) {
1632eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = ++V.cbegin(), i2 = V.cend();
1633eb90692dSAdam Balogh
1634eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1635eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1636eb90692dSAdam Balogh
1637eb90692dSAdam Balogh auto i3 = V.erase(i1);
1638eb90692dSAdam Balogh
1639eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1640eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1641eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1642eb90692dSAdam Balogh
1643ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}} FIXME: Should be $V.begin() + 1
1644eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.begin() + 2
1645eb90692dSAdam Balogh }
1646eb90692dSAdam Balogh
vector_erase_unknown(std::vector<int> & V)1647eb90692dSAdam Balogh void vector_erase_unknown(std::vector<int> &V) {
1648eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = return_any_iterator(V.cbegin()), i2 = V.cend();
1649eb90692dSAdam Balogh
1650eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1651eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1652eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1653eb90692dSAdam Balogh
1654eb90692dSAdam Balogh auto i3 = V.erase(i1);
1655eb90692dSAdam Balogh
1656eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1657eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1658eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1659eb90692dSAdam Balogh
1660ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1661eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 + 1
1662eb90692dSAdam Balogh }
1663eb90692dSAdam Balogh
vector_erase_ahead_of_end(std::vector<int> & V)1664eb90692dSAdam Balogh void vector_erase_ahead_of_end(std::vector<int> &V) {
1665eb90692dSAdam Balogh auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
1666eb90692dSAdam Balogh
1667eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1668eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1669eb90692dSAdam Balogh
1670eb90692dSAdam Balogh auto i3 = V.erase(i1);
1671eb90692dSAdam Balogh
1672eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1673eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1674eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1675eb90692dSAdam Balogh
1676ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1677eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.end()
1678eb90692dSAdam Balogh }
1679eb90692dSAdam Balogh
1680eb90692dSAdam Balogh /// std::deque-like containers: All iterators are invalidated, unless the erased
1681eb90692dSAdam Balogh /// element is at the end or the beginning of the
1682eb90692dSAdam Balogh /// container, in which case only the iterators to
1683eb90692dSAdam Balogh /// the erased element are invalidated. The
1684eb90692dSAdam Balogh /// past-the-end iterator is also invalidated unless
1685eb90692dSAdam Balogh /// the erased element is at the beginning of the
1686eb90692dSAdam Balogh /// container and the last element is not erased.
1687eb90692dSAdam Balogh
deque_erase_begin(std::deque<int> & D)1688eb90692dSAdam Balogh void deque_erase_begin(std::deque<int> &D) {
1689eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = ++D.cbegin(), i2 = D.cend();
1690eb90692dSAdam Balogh
1691eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1692eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1693eb90692dSAdam Balogh
1694eb90692dSAdam Balogh auto i3 = D.erase(i0);
1695eb90692dSAdam Balogh
1696eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1697eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1698eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1699eb90692dSAdam Balogh
1700eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.begin() + 1
1701eb90692dSAdam Balogh }
1702eb90692dSAdam Balogh
deque_erase_behind_begin(std::deque<int> & D,int n)1703eb90692dSAdam Balogh void deque_erase_behind_begin(std::deque<int> &D, int n) {
1704eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = ++D.cbegin(), i2 = D.cend();
1705eb90692dSAdam Balogh
1706eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1707eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1708eb90692dSAdam Balogh
1709eb90692dSAdam Balogh auto i3 = D.erase(i1);
1710eb90692dSAdam Balogh
1711eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1712eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1713eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1714eb90692dSAdam Balogh
1715eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.begin() + 2
1716eb90692dSAdam Balogh }
1717eb90692dSAdam Balogh
deque_erase_unknown(std::deque<int> & D)1718eb90692dSAdam Balogh void deque_erase_unknown(std::deque<int> &D) {
1719eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = return_any_iterator(D.cbegin()), i2 = D.cend();
1720eb90692dSAdam Balogh
1721eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1722eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1723eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1724eb90692dSAdam Balogh
1725eb90692dSAdam Balogh auto i3 = D.erase(i1);
1726eb90692dSAdam Balogh
1727eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1728eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1729eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1730eb90692dSAdam Balogh
1731eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 + 1
1732eb90692dSAdam Balogh }
1733eb90692dSAdam Balogh
deque_erase_ahead_of_end(std::deque<int> & D)1734eb90692dSAdam Balogh void deque_erase_ahead_of_end(std::deque<int> &D) {
1735eb90692dSAdam Balogh auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
1736eb90692dSAdam Balogh
1737eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1738eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1739eb90692dSAdam Balogh
1740eb90692dSAdam Balogh auto i3 = D.erase(i1);
1741eb90692dSAdam Balogh
1742eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1743eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1744eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1745eb90692dSAdam Balogh
1746eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end()
1747eb90692dSAdam Balogh }
1748eb90692dSAdam Balogh
1749eb90692dSAdam Balogh /// erase_after() [std::forward_list-like containers]
1750eb90692dSAdam Balogh ///
1751eb90692dSAdam Balogh /// - Design decision: shifts positions to the <-LEFT<- (i.e. all iterator
1752eb90692dSAdam Balogh /// begind of the ereased element are decremented; if the
1753eb90692dSAdam Balogh /// relation between the position of the erased element
1754eb90692dSAdam Balogh /// and the past-the-end position of the container is known,
1755eb90692dSAdam Balogh /// the past-the-end position of the container is also
1756eb90692dSAdam Balogh /// decremented).
1757eb90692dSAdam Balogh ///
1758eb90692dSAdam Balogh /// - Iterators to the erased element are invalidated. Other iterators are not
1759eb90692dSAdam Balogh /// affected.
1760eb90692dSAdam Balogh
1761eb90692dSAdam Balogh
forward_list_erase_after_begin(std::forward_list<int> & FL)1762eb90692dSAdam Balogh void forward_list_erase_after_begin(std::forward_list<int> &FL) {
1763eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = ++FL.cbegin(), i2 = i1, i3 = FL.cend();
1764eb90692dSAdam Balogh ++i2;
1765eb90692dSAdam Balogh
1766eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1767eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1768eb90692dSAdam Balogh
1769eb90692dSAdam Balogh auto i4 = FL.erase_after(i0);
1770eb90692dSAdam Balogh
1771eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1772eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1773eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1774eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i3)); //expected-warning{{TRUE}}
1775eb90692dSAdam Balogh
1776ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1777ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.begin() + 2{{$}}}} FIXME: Should be $FL.begin() + 1
1778eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i4)); FIXME: expect warning $FL.begin() + 1
1779ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i3)); // expected-warning-re {{$FL.end(){{$}}}}
1780eb90692dSAdam Balogh }
1781eb90692dSAdam Balogh
forward_list_erase_after_unknown(std::forward_list<int> & FL)1782eb90692dSAdam Balogh void forward_list_erase_after_unknown(std::forward_list<int> &FL) {
1783eb90692dSAdam Balogh auto i0 = FL.cbegin(), i1 = return_any_iterator(FL.cbegin()), i2 = i1,
1784eb90692dSAdam Balogh i3 = i1, i4 = FL.cend();
1785eb90692dSAdam Balogh ++i2;
1786eb90692dSAdam Balogh ++i3;
1787eb90692dSAdam Balogh ++i3;
1788eb90692dSAdam Balogh
1789eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1790eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1791eb90692dSAdam Balogh clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1792eb90692dSAdam Balogh
1793eb90692dSAdam Balogh auto i5 = FL.erase_after(i1);
1794eb90692dSAdam Balogh
1795eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1796eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1797eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1798eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i3)); //expected-warning{{TRUE}}
1799eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_validity(i4)); //expected-warning{{TRUE}}
1800eb90692dSAdam Balogh
1801ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1802ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$i1{{$}}}}
1803ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i3)); // expected-warning-re {{$i1 + 2{{$}}}} FIXME: Should be $i1 + 1
1804eb90692dSAdam Balogh // clang_analyzer_express(clang_analyzer_iterator_position(i5)); FIXME: expect warning $i1 + 1
1805ea563daaSAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i4)); // expected-warning-re {{$FL.end(){{$}}}}
1806eb90692dSAdam Balogh }
1807eb90692dSAdam Balogh
1808eb90692dSAdam Balogh struct simple_iterator_base {
1809eb90692dSAdam Balogh simple_iterator_base();
1810eb90692dSAdam Balogh simple_iterator_base(const simple_iterator_base& rhs);
1811eb90692dSAdam Balogh simple_iterator_base &operator=(const simple_iterator_base& rhs);
1812eb90692dSAdam Balogh virtual ~simple_iterator_base();
1813eb90692dSAdam Balogh bool friend operator==(const simple_iterator_base &lhs,
1814eb90692dSAdam Balogh const simple_iterator_base &rhs);
1815eb90692dSAdam Balogh bool friend operator!=(const simple_iterator_base &lhs,
1816eb90692dSAdam Balogh const simple_iterator_base &rhs);
1817eb90692dSAdam Balogh private:
1818eb90692dSAdam Balogh int *ptr;
1819eb90692dSAdam Balogh };
1820eb90692dSAdam Balogh
1821eb90692dSAdam Balogh struct simple_derived_iterator: public simple_iterator_base {
1822eb90692dSAdam Balogh int& operator*();
1823eb90692dSAdam Balogh int* operator->();
1824eb90692dSAdam Balogh simple_iterator_base &operator++();
1825eb90692dSAdam Balogh simple_iterator_base operator++(int);
1826eb90692dSAdam Balogh simple_iterator_base &operator--();
1827eb90692dSAdam Balogh simple_iterator_base operator--(int);
1828eb90692dSAdam Balogh };
1829eb90692dSAdam Balogh
1830eb90692dSAdam Balogh struct simple_container {
1831eb90692dSAdam Balogh typedef simple_derived_iterator iterator;
1832eb90692dSAdam Balogh
1833eb90692dSAdam Balogh iterator begin();
1834eb90692dSAdam Balogh iterator end();
1835eb90692dSAdam Balogh };
1836eb90692dSAdam Balogh
good_derived(simple_container c)1837eb90692dSAdam Balogh void good_derived(simple_container c) {
1838eb90692dSAdam Balogh auto i0 = c.end();
1839eb90692dSAdam Balogh
1840eb90692dSAdam Balogh if (i0 != c.end()) {
1841eb90692dSAdam Balogh clang_analyzer_warnIfReached();
1842eb90692dSAdam Balogh }
1843eb90692dSAdam Balogh }
1844eb90692dSAdam Balogh
iter_diff(std::vector<int> & V)1845eb90692dSAdam Balogh void iter_diff(std::vector<int> &V) {
1846eb90692dSAdam Balogh auto i0 = V.begin(), i1 = V.end();
1847eb90692dSAdam Balogh ptrdiff_t len = i1 - i0; // no-crash
1848eb90692dSAdam Balogh }
1849eb90692dSAdam Balogh
deferred_assumption(std::vector<int> & V,int e)1850eb90692dSAdam Balogh void deferred_assumption(std::vector<int> &V, int e) {
1851eb90692dSAdam Balogh const auto first = V.begin();
1852eb90692dSAdam Balogh const auto comp1 = (first != V.end()), comp2 = (first == V.end());
1853eb90692dSAdam Balogh if (comp1) {
1854eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_container_end(V) ==
1855eb90692dSAdam Balogh clang_analyzer_iterator_position(first)); // expected-warning@-1{{FALSE}}
1856eb90692dSAdam Balogh }
1857eb90692dSAdam Balogh }
1858eb90692dSAdam Balogh
loop(std::vector<int> & V,int e)1859eb90692dSAdam Balogh void loop(std::vector<int> &V, int e) {
1860eb90692dSAdam Balogh auto start = V.begin();
1861eb90692dSAdam Balogh while (true) {
1862eb90692dSAdam Balogh auto item = std::find(start, V.end(), e);
1863eb90692dSAdam Balogh if (item == V.end())
1864eb90692dSAdam Balogh break;
1865eb90692dSAdam Balogh
1866eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_container_end(V) ==
1867eb90692dSAdam Balogh clang_analyzer_iterator_position(item)); // expected-warning@-1{{FALSE}}
1868eb90692dSAdam Balogh }
1869eb90692dSAdam Balogh }
1870eb90692dSAdam Balogh
1871eb90692dSAdam Balogh template <typename InputIterator, typename T>
nonStdFind(InputIterator first,InputIterator last,const T & val)1872eb90692dSAdam Balogh InputIterator nonStdFind(InputIterator first, InputIterator last,
1873eb90692dSAdam Balogh const T &val) {
1874eb90692dSAdam Balogh for (auto i = first; i != last; ++i) {
1875eb90692dSAdam Balogh if (*i == val) {
1876eb90692dSAdam Balogh return i;
1877eb90692dSAdam Balogh }
1878eb90692dSAdam Balogh }
1879eb90692dSAdam Balogh return last;
1880eb90692dSAdam Balogh }
1881eb90692dSAdam Balogh
non_std_find(std::vector<int> & V,int e)1882eb90692dSAdam Balogh void non_std_find(std::vector<int> &V, int e) {
1883eb90692dSAdam Balogh auto first = nonStdFind(V.begin(), V.end(), e);
1884eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_container_end(V) ==
1885eb90692dSAdam Balogh clang_analyzer_iterator_position(first)); // expected-warning@-1{{FALSE}} expected-warning@-1{{TRUE}}
1886eb90692dSAdam Balogh if (V.end() != first) {
1887eb90692dSAdam Balogh clang_analyzer_eval(clang_analyzer_container_end(V) ==
1888eb90692dSAdam Balogh clang_analyzer_iterator_position(first)); // expected-warning@-1{{FALSE}}
1889eb90692dSAdam Balogh }
1890eb90692dSAdam Balogh }
1891eb90692dSAdam Balogh
18929e63b190SAdam Balogh template<typename T>
18939e63b190SAdam Balogh struct cont_with_ptr_iterator {
18949e63b190SAdam Balogh typedef T* iterator;
18959e63b190SAdam Balogh T* begin() const;
18969e63b190SAdam Balogh T* end() const;
18979e63b190SAdam Balogh };
18989e63b190SAdam Balogh
begin_ptr_iterator(const cont_with_ptr_iterator<int> & c)18999e63b190SAdam Balogh void begin_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
19009e63b190SAdam Balogh auto i = c.begin();
19019e63b190SAdam Balogh
19029e63b190SAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i) == &c); // expected-warning{{TRUE}}
19039e63b190SAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
19049e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.begin()}}
19059e63b190SAdam Balogh
19069e63b190SAdam Balogh if (i != c.begin()) {
19079e63b190SAdam Balogh clang_analyzer_warnIfReached();
19089e63b190SAdam Balogh }
19099e63b190SAdam Balogh }
19109e63b190SAdam Balogh
prefix_increment_ptr_iterator(const cont_with_ptr_iterator<int> & c)19119e63b190SAdam Balogh void prefix_increment_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
19129e63b190SAdam Balogh auto i = c.begin();
19139e63b190SAdam Balogh
19149e63b190SAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
19159e63b190SAdam Balogh
19169e63b190SAdam Balogh auto j = ++i;
19179e63b190SAdam Balogh
19189e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.begin() + 1}}
19199e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning{{$c.begin() + 1}}
19209e63b190SAdam Balogh }
19219e63b190SAdam Balogh
prefix_decrement_ptr_iterator(const cont_with_ptr_iterator<int> & c)19229e63b190SAdam Balogh void prefix_decrement_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
19239e63b190SAdam Balogh auto i = c.end();
19249e63b190SAdam Balogh
19259e63b190SAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(c), "$c.end()");
19269e63b190SAdam Balogh
19279e63b190SAdam Balogh auto j = --i;
19289e63b190SAdam Balogh
19299e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.end() - 1}}
19309e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning{{$c.end() - 1}}
19319e63b190SAdam Balogh }
19329e63b190SAdam Balogh
postfix_increment_ptr_iterator(const cont_with_ptr_iterator<int> & c)19339e63b190SAdam Balogh void postfix_increment_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
19349e63b190SAdam Balogh auto i = c.begin();
19359e63b190SAdam Balogh
19369e63b190SAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
19379e63b190SAdam Balogh
19389e63b190SAdam Balogh auto j = i++;
19399e63b190SAdam Balogh
19409e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.begin() + 1}}
19419e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning{{$c.begin()}}
19429e63b190SAdam Balogh }
19439e63b190SAdam Balogh
postfix_decrement_ptr_iterator(const cont_with_ptr_iterator<int> & c)19449e63b190SAdam Balogh void postfix_decrement_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
19459e63b190SAdam Balogh auto i = c.end();
19469e63b190SAdam Balogh
19479e63b190SAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(c), "$c.end()");
19489e63b190SAdam Balogh
19499e63b190SAdam Balogh auto j = i--;
19509e63b190SAdam Balogh
19519e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.end() - 1}}
19529e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning{{$c.end()}}
19539e63b190SAdam Balogh }
19549e63b190SAdam Balogh
plus_equal_ptr_iterator(const cont_with_ptr_iterator<int> & c)19559e63b190SAdam Balogh void plus_equal_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
19569e63b190SAdam Balogh auto i = c.begin();
19579e63b190SAdam Balogh
19589e63b190SAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
19599e63b190SAdam Balogh
19609e63b190SAdam Balogh i += 2;
19619e63b190SAdam Balogh
19629e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.begin() + 2}}
19639e63b190SAdam Balogh }
19649e63b190SAdam Balogh
minus_equal_ptr_iterator(const cont_with_ptr_iterator<int> & c)19659e63b190SAdam Balogh void minus_equal_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
19669e63b190SAdam Balogh auto i = c.end();
19679e63b190SAdam Balogh
19689e63b190SAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(c), "$c.end()");
19699e63b190SAdam Balogh
19709e63b190SAdam Balogh i -= 2;
19719e63b190SAdam Balogh
19729e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.end() - 2}}
19739e63b190SAdam Balogh }
19749e63b190SAdam Balogh
minus_equal_ptr_iterator_variable(const cont_with_ptr_iterator<int> & c,int n)1975a59d4ae4SAdam Balogh void minus_equal_ptr_iterator_variable(const cont_with_ptr_iterator<int> &c,
1976a59d4ae4SAdam Balogh int n) {
1977a59d4ae4SAdam Balogh auto i = c.end();
1978a59d4ae4SAdam Balogh
1979a59d4ae4SAdam Balogh i -= n; // no-crash
1980a59d4ae4SAdam Balogh }
1981a59d4ae4SAdam Balogh
plus_lhs_ptr_iterator(const cont_with_ptr_iterator<int> & c)1982*141cb8a1SEndre Fülöp void plus_lhs_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
19839e63b190SAdam Balogh auto i1 = c.begin();
19849e63b190SAdam Balogh
19859e63b190SAdam Balogh clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
19869e63b190SAdam Balogh
19879e63b190SAdam Balogh auto i2 = i1 + 2;
19889e63b190SAdam Balogh
19899e63b190SAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &c); // expected-warning{{TRUE}}
19909e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$c.begin()}}
19919e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$c.begin() + 2}}
19929e63b190SAdam Balogh }
19939e63b190SAdam Balogh
plus_rhs_ptr_iterator(const cont_with_ptr_iterator<int> & c)1994*141cb8a1SEndre Fülöp void plus_rhs_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
1995*141cb8a1SEndre Fülöp auto i1 = c.begin();
1996*141cb8a1SEndre Fülöp
1997*141cb8a1SEndre Fülöp clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
1998*141cb8a1SEndre Fülöp
1999*141cb8a1SEndre Fülöp auto i2 = 2 + i1;
2000*141cb8a1SEndre Fülöp
2001*141cb8a1SEndre Fülöp clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &c); // expected-warning{{TRUE}}
2002*141cb8a1SEndre Fülöp clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$c.begin()}}
2003*141cb8a1SEndre Fülöp clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$c.begin() + 2}}
2004*141cb8a1SEndre Fülöp }
2005*141cb8a1SEndre Fülöp
minus_ptr_iterator(const cont_with_ptr_iterator<int> & c)20069e63b190SAdam Balogh void minus_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
20079e63b190SAdam Balogh auto i1 = c.end();
20089e63b190SAdam Balogh
20099e63b190SAdam Balogh clang_analyzer_denote(clang_analyzer_container_end(c), "$c.end()");
20109e63b190SAdam Balogh
20119e63b190SAdam Balogh auto i2 = i1 - 2;
20129e63b190SAdam Balogh
20139e63b190SAdam Balogh clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &c); // expected-warning{{TRUE}}
20149e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$c.end()}}
20159e63b190SAdam Balogh clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$c.end() - 2}}
20169e63b190SAdam Balogh }
20179e63b190SAdam Balogh
ptr_iter_diff(cont_with_ptr_iterator<int> & c)2018a59d4ae4SAdam Balogh void ptr_iter_diff(cont_with_ptr_iterator<int> &c) {
2019a59d4ae4SAdam Balogh auto i0 = c.begin(), i1 = c.end();
2020a59d4ae4SAdam Balogh ptrdiff_t len = i1 - i0; // no-crash
2021a59d4ae4SAdam Balogh }
2022a59d4ae4SAdam Balogh
ptr_iter_cmp_nullptr(cont_with_ptr_iterator<int> & c)2023a59d4ae4SAdam Balogh void ptr_iter_cmp_nullptr(cont_with_ptr_iterator<int> &c) {
2024a59d4ae4SAdam Balogh auto i0 = c.begin();
2025a59d4ae4SAdam Balogh if (i0 != nullptr) // no-crash
2026a59d4ae4SAdam Balogh ++i0;
2027a59d4ae4SAdam Balogh }
2028a59d4ae4SAdam Balogh
2029eb90692dSAdam Balogh void clang_analyzer_printState();
2030eb90692dSAdam Balogh
print_state(std::vector<int> & V)2031eb90692dSAdam Balogh void print_state(std::vector<int> &V) {
2032eb90692dSAdam Balogh const auto i0 = V.cbegin();
2033eb90692dSAdam Balogh clang_analyzer_printState();
2034eb90692dSAdam Balogh
2035eb90692dSAdam Balogh // CHECK: "checker_messages": [
2036eb90692dSAdam Balogh // CHECK: { "checker": "alpha.cplusplus.IteratorModeling", "messages": [
2037eb90692dSAdam Balogh // CHECK-NEXT: "Iterator Positions :",
2038eb90692dSAdam Balogh // CHECK-NEXT: "i0 : Valid ; Container == SymRegion{reg_$[[#]]<std::vector<int> & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
2039eb90692dSAdam Balogh // CHECK-NEXT: ]}
2040eb90692dSAdam Balogh
2041ea563daaSAdam Balogh *i0;
2042c79745edSAdam Balogh const auto i1 = V.cend();
2043eb90692dSAdam Balogh clang_analyzer_printState();
2044eb90692dSAdam Balogh
2045eb90692dSAdam Balogh // CHECK: "checker_messages": [
2046eb90692dSAdam Balogh // CHECK: { "checker": "alpha.cplusplus.IteratorModeling", "messages": [
2047eb90692dSAdam Balogh // CHECK-NEXT: "Iterator Positions :",
2048c79745edSAdam Balogh // CHECK-NEXT: "i1 : Valid ; Container == SymRegion{reg_$[[#]]<std::vector<int> & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
2049eb90692dSAdam Balogh // CHECK-NEXT: ]}
2050ea563daaSAdam Balogh
2051c79745edSAdam Balogh *i1;
2052eb90692dSAdam Balogh }
2053