[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Analysis / iterator-modeling.cpp
blobf1538839d06c8e7a77ca38a66c2095eae183cb0a
1 // 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
3 // 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
5 // 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
7 // 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
9 // 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
11 // 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
13 #include "Inputs/system-header-simulator-cxx.h"
15 template <typename Container>
16 long clang_analyzer_container_begin(const Container&);
17 template <typename Container>
18 long clang_analyzer_container_end(const Container&);
19 template <typename Iterator>
20 long clang_analyzer_iterator_position(const Iterator&);
21 long clang_analyzer_iterator_position(int*);
22 template <typename Iterator>
23 void* clang_analyzer_iterator_container(const Iterator&);
24 template <typename Iterator>
25 bool clang_analyzer_iterator_validity(const Iterator&);
27 void clang_analyzer_denote(long, const char*);
28 void clang_analyzer_express(long);
29 void clang_analyzer_eval(bool);
30 void clang_analyzer_warnIfReached();
32 void begin(const std::vector<int> &v) {
33 auto i = v.begin();
35 clang_analyzer_eval(clang_analyzer_iterator_container(i) == &v); // expected-warning{{TRUE}}
36 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
37 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin(){{$}}}}
39 if (i != v.begin()) {
40 clang_analyzer_warnIfReached();
44 void end(const std::vector<int> &v) {
45 auto i = v.end();
47 clang_analyzer_eval(clang_analyzer_iterator_container(i) == &v); // expected-warning{{TRUE}}
48 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
49 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end(){{$}}}}
51 if (i != v.end()) {
52 clang_analyzer_warnIfReached();
56 void prefix_increment(const std::vector<int> &v) {
57 auto i = v.begin();
59 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
61 auto j = ++i;
63 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin() + 1{{$}}}}
64 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.begin() + 1{{$}}}}
67 void prefix_decrement(const std::vector<int> &v) {
68 auto i = v.end();
70 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
72 auto j = --i;
74 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end() - 1{{$}}}}
75 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.end() - 1{{$}}}}
78 void postfix_increment(const std::vector<int> &v) {
79 auto i = v.begin();
81 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
83 auto j = i++;
85 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin() + 1{{$}}}}
86 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.begin(){{$}}}}
89 void postfix_decrement(const std::vector<int> &v) {
90 auto i = v.end();
92 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
94 auto j = i--;
96 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end() - 1{{$}}}}
97 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.end(){{$}}}}
100 void plus_equal(const std::vector<int> &v) {
101 auto i = v.begin();
103 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
105 i += 2;
107 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin() + 2{{$}}}}
110 void plus_equal_negative(const std::vector<int> &v) {
111 auto i = v.end();
113 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
115 i += -2;
117 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end() - 2{{$}}}}
120 void minus_equal(const std::vector<int> &v) {
121 auto i = v.end();
123 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
125 i -= 2;
127 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end() - 2{{$}}}}
130 void minus_equal_negative(const std::vector<int> &v) {
131 auto i = v.begin();
133 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
135 i -= -2;
137 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin() + 2{{$}}}}
140 void copy(const std::vector<int> &v) {
141 auto i1 = v.end();
143 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
145 auto i2 = i1;
147 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
148 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end(){{$}}}}
149 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end(){{$}}}}
152 void plus_lhs(const std::vector<int> &v) {
153 auto i1 = v.begin();
155 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
157 auto i2 = i1 + 2;
159 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
160 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re{{$v.begin(){{$}}}}
161 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re{{$v.begin() + 2{{$}}}}
164 void plus_rhs(const std::vector<int> &v) {
165 auto i1 = v.begin();
167 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
169 auto i2 = 2 + i1;
171 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
172 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re{{$v.begin(){{$}}}}
173 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re{{$v.begin() + 2{{$}}}}
176 void plus_lhs_negative(const std::vector<int> &v) {
177 auto i1 = v.end();
179 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
181 auto i2 = i1 + (-2);
183 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
184 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end(){{$}}}}
185 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end() - 2{{$}}}}
188 void plus_rhs_negative(const std::vector<int> &v) {
189 auto i1 = v.end();
191 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
193 auto i2 = (-2) + i1;
195 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
196 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end(){{$}}}}
197 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end() - 2{{$}}}}
200 void minus(const std::vector<int> &v) {
201 auto i1 = v.end();
203 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
205 auto i2 = i1 - 2;
207 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
208 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end(){{$}}}}
209 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end() - 2{{$}}}}
212 void minus_negative(const std::vector<int> &v) {
213 auto i1 = v.begin();
215 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
217 auto i2 = i1 - (-2);
219 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &v); // expected-warning{{TRUE}}
220 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.begin(){{$}}}}
221 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.begin() + 2{{$}}}}
224 void copy_and_increment1(const std::vector<int> &v) {
225 auto i1 = v.begin();
227 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
229 auto i2 = i1;
230 ++i1;
232 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.begin() + 1{{$}}}}
233 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.begin(){{$}}}}
236 void copy_and_increment2(const std::vector<int> &v) {
237 auto i1 = v.begin();
239 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
241 auto i2 = i1;
242 ++i2;
244 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.begin(){{$}}}}
245 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.begin() + 1{{$}}}}
248 void copy_and_decrement1(const std::vector<int> &v) {
249 auto i1 = v.end();
251 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
253 auto i2 = i1;
254 --i1;
256 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end() - 1{{$}}}}
257 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end(){{$}}}}
260 void copy_and_decrement2(const std::vector<int> &v) {
261 auto i1 = v.end();
263 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
265 auto i2 = i1;
266 --i2;
268 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$v.end(){{$}}}}
269 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$v.end() - 1{{$}}}}
272 /// std::advance(), std::prev(), std::next()
274 void std_advance_minus(const std::vector<int> &v) {
275 auto i = v.end();
277 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
279 std::advance(i, -1);
281 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.end() - 1{{$}}}}
284 void std_advance_plus(const std::vector<int> &v) {
285 auto i = v.begin();
287 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
289 std::advance(i, 1);
291 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning-re {{$v.begin() + 1{{$}}}}
294 void std_prev(const std::vector<int> &v) {
295 auto i = v.end();
297 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
299 auto j = std::prev(i);
301 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.end() - 1{{$}}}}
304 void std_prev2(const std::vector<int> &v) {
305 auto i = v.end();
307 clang_analyzer_denote(clang_analyzer_container_end(v), "$v.end()");
309 auto j = std::prev(i, 2);
311 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.end() - 2{{$}}}}
314 void std_next(const std::vector<int> &v) {
315 auto i = v.begin();
317 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
319 auto j = std::next(i);
321 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.begin() + 1{{$}}}}
324 void std_next2(const std::vector<int> &v) {
325 auto i = v.begin();
327 clang_analyzer_denote(clang_analyzer_container_begin(v), "$v.begin()");
329 auto j = std::next(i, 2);
331 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning-re {{$v.begin() + 2{{$}}}}
334 ////////////////////////////////////////////////////////////////////////////////
336 /// C O N T A I N E R A S S I G N M E N T S
338 ////////////////////////////////////////////////////////////////////////////////
340 // Copy
342 void list_copy_assignment(std::list<int> &L1, const std::list<int> &L2) {
343 auto i0 = L1.cbegin();
344 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
345 L1 = L2;
346 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
349 void vector_copy_assignment(std::vector<int> &V1, const std::vector<int> &V2) {
350 auto i0 = V1.cbegin();
351 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
352 V1 = V2;
353 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
356 void deque_copy_assignment(std::deque<int> &D1, const std::deque<int> &D2) {
357 auto i0 = D1.cbegin();
358 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
359 D1 = D2;
360 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
363 void forward_list_copy_assignment(std::forward_list<int> &FL1,
364 const std::forward_list<int> &FL2) {
365 auto i0 = FL1.cbegin();
366 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
367 FL1 = FL2;
368 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
371 // Move
373 void list_move_assignment(std::list<int> &L1, std::list<int> &L2) {
374 auto i0 = L1.cbegin(), i1 = L2.cbegin(), i2 = --L2.cend(), i3 = L2.cend();
376 clang_analyzer_denote(clang_analyzer_container_begin(L2), "$L2.begin()");
377 clang_analyzer_denote(clang_analyzer_container_end(L2), "$L2.end()");
379 L1 = std::move(L2);
381 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
382 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
383 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
384 clang_analyzer_eval(clang_analyzer_iterator_validity(i3)); //expected-warning{{TRUE}} FIXME: Should be FALSE.
386 clang_analyzer_eval(clang_analyzer_iterator_container(i1) == &L1); // expected-warning{{TRUE}}
387 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &L1); // expected-warning{{TRUE}}
389 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L2.begin(){{$}}}}
392 void vector_move_assignment(std::vector<int> &V1, std::vector<int> &V2) {
393 auto i0 = V1.cbegin(), i1 = V2.cbegin(), i2 = --V2.cend(), i3 = V2.cend();
395 clang_analyzer_denote(clang_analyzer_container_begin(V2), "$V2.begin()");
397 V1 = std::move(V2);
399 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
400 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
401 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
402 clang_analyzer_eval(clang_analyzer_iterator_validity(i3)); //expected-warning{{TRUE}} FIXME: Should be FALSE.
404 clang_analyzer_eval(clang_analyzer_iterator_container(i1) == &V1); // expected-warning{{TRUE}}
405 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &V1); // expected-warning{{TRUE}}
407 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V2.begin(){{$}}}}
410 void deque_move_assignment(std::deque<int> &D1, std::deque<int> &D2) {
411 auto i0 = D1.cbegin(), i1 = D2.cbegin(), i2 = --D2.cend(), i3 = D2.cend();
413 clang_analyzer_denote(clang_analyzer_container_begin(D2), "$D2.begin()");
415 D1 = std::move(D2);
417 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
418 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
419 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
420 clang_analyzer_eval(clang_analyzer_iterator_validity(i3)); //expected-warning{{TRUE}} FIXME: Should be FALSE.
422 clang_analyzer_eval(clang_analyzer_iterator_container(i1) == &D1); // expected-warning{{TRUE}}
423 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &D1); // expected-warning{{TRUE}}
425 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$D2.begin(){{$}}}}
428 void forward_list_move_assignment(std::forward_list<int> &FL1,
429 std::forward_list<int> &FL2) {
430 auto i0 = FL1.cbegin(), i1 = FL2.cbegin(), i2 = FL2.cend();
432 clang_analyzer_denote(clang_analyzer_container_begin(FL2), "$FL2.begin()");
434 FL1 = std::move(FL2);
436 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
437 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
438 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}} FIXME: Should be FALSE.
440 clang_analyzer_eval(clang_analyzer_iterator_container(i1) == &FL1); // expected-warning{{TRUE}}
442 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL2.begin(){{$}}}}
446 ////////////////////////////////////////////////////////////////////////////////
448 /// C O N T A I N E R M O D I F I E R S
450 ////////////////////////////////////////////////////////////////////////////////
452 /// assign()
454 /// - Invalidates all iterators, including the past-the-end iterator for all
455 /// container types.
457 void list_assign(std::list<int> &L, int n) {
458 auto i0 = L.cbegin(), i1 = L.cend();
459 L.assign(10, n);
460 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
461 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
464 void vector_assign(std::vector<int> &V, int n) {
465 auto i0 = V.cbegin(), i1 = V.cend();
466 V.assign(10, n);
467 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
468 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
471 void deque_assign(std::deque<int> &D, int n) {
472 auto i0 = D.cbegin(), i1 = D.cend();
473 D.assign(10, n);
474 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
475 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
478 void forward_list_assign(std::forward_list<int> &FL, int n) {
479 auto i0 = FL.cbegin(), i1 = FL.cend();
480 FL.assign(10, n);
481 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
482 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
485 /// clear()
487 /// - Invalidates all iterators, including the past-the-end iterator for all
488 /// container types.
490 void list_clear(std::list<int> &L) {
491 auto i0 = L.cbegin(), i1 = L.cend();
492 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
493 L.clear();
494 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
497 void vector_clear(std::vector<int> &V) {
498 auto i0 = V.cbegin(), i1 = V.cend();
499 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
500 V.clear();
501 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
504 void deque_clear(std::deque<int> &D) {
505 auto i0 = D.cbegin(), i1 = D.cend();
506 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
507 D.clear();
508 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
511 void forward_list_clear(std::forward_list<int> &FL) {
512 auto i0 = FL.cbegin(), i1 = FL.cend();
513 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
514 FL.clear();
515 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
518 /// push_back()
520 /// - Design decision: extends containers to the ->RIGHT-> (i.e. the
521 /// past-the-end position of the container is incremented).
523 /// - Iterator invalidation rules depend the container type.
525 /// std::list-like containers: No iterators are invalidated.
527 void list_push_back(std::list<int> &L, int n) {
528 auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
530 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
531 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
533 L.push_back(n);
535 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
536 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
537 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
539 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
540 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}}
541 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}} FIXME: Should be $L.end() + 1
544 /// std::vector-like containers: The past-the-end iterator is invalidated.
546 void vector_push_back(std::vector<int> &V, int n) {
547 auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
549 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
550 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
552 V.push_back(n);
554 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
555 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
556 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
558 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
559 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V.end() - 1{{$}}}}
562 /// std::deque-like containers: All iterators, including the past-the-end
563 /// iterator, are invalidated.
565 void deque_push_back(std::deque<int> &D, int n) {
566 auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
568 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
569 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
571 D.push_back(n);
573 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
574 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
575 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
578 /// emplace_back()
580 /// - Design decision: extends containers to the ->RIGHT-> (i.e. the
581 /// past-the-end position of the container is incremented).
583 /// - Iterator invalidation rules depend the container type.
585 /// std::list-like containers: No iterators are invalidated.
587 void list_emplace_back(std::list<int> &L, int n) {
588 auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
590 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
591 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
593 L.emplace_back(n);
595 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
596 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
597 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
599 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
600 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}}
601 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}} FIXME: Should be $L.end() + 1
604 /// std::vector-like containers: The past-the-end iterator is invalidated.
606 void vector_emplace_back(std::vector<int> &V, int n) {
607 auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
609 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
610 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
612 V.emplace_back(n);
614 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
615 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
616 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
618 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
619 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V.end() - 1{{$}}}}
622 /// std::deque-like containers: All iterators, including the past-the-end
623 /// iterator, are invalidated.
625 void deque_emplace_back(std::deque<int> &D, int n) {
626 auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
628 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
629 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
631 D.emplace_back(n);
633 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
634 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
635 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
638 /// pop_back()
640 /// - Design decision: shrinks containers to the <-LEFT<- (i.e. the
641 /// past-the-end position of the container is decremented).
643 /// - Iterator invalidation rules depend the container type.
645 /// std::list-like containers: Iterators to the last element are invalidated.
647 void list_pop_back(std::list<int> &L, int n) {
648 auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
650 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
651 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
653 L.pop_back();
655 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
656 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
657 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
659 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
660 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}} FIXME: Should be $L.end() - 1
663 /// std::vector-like containers: Iterators to the last element, as well as the
664 /// past-the-end iterator, are invalidated.
666 void vector_pop_back(std::vector<int> &V, int n) {
667 auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
669 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
670 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
672 V.pop_back();
674 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
675 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
676 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
678 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
681 /// std::deque-like containers: Iterators to the last element are invalidated.
682 /// The past-the-end iterator is also invalidated.
683 /// Other iterators are not affected.
685 void deque_pop_back(std::deque<int> &D, int n) {
686 auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
688 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
689 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
691 D.pop_back();
693 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
694 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
695 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
697 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$D.begin(){{$}}}}
700 /// push_front()
702 /// - Design decision: extends containers to the <-LEFT<- (i.e. the first
703 /// position of the container is decremented).
705 /// - Iterator invalidation rules depend the container type.
707 /// std::list-like containers: No iterators are invalidated.
709 void list_push_front(std::list<int> &L, int n) {
710 auto i0 = L.cbegin(), i1 = L.cend();
712 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
713 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
715 L.push_front(n);
717 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
718 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
720 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
721 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end(){{$}}}}
724 /// std::deque-like containers: All iterators, including the past-the-end
725 /// iterator, are invalidated.
727 void deque_push_front(std::deque<int> &D, int n) {
728 auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
730 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
731 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
733 D.push_front(n);
735 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
736 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
737 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
740 /// std::forward_list-like containers: No iterators are invalidated.
742 void forward_list_push_front(std::forward_list<int> &FL, int n) {
743 auto i0 = FL.cbegin(), i1 = FL.cend();
745 clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
746 clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
748 FL.push_front(n);
750 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
751 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
753 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
754 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.end(){{$}}}}
757 /// emplace_front()
759 /// - Design decision: extends containers to the <-LEFT<- (i.e. the first
760 /// position of the container is decremented).
762 /// - Iterator invalidation rules depend the container type.
764 /// std::list-like containers: No iterators are invalidated.
766 void list_emplace_front(std::list<int> &L, int n) {
767 auto i0 = L.cbegin(), i1 = L.cend();
769 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
770 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
772 L.emplace_front(n);
774 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
775 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
777 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
778 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end(){{$}}}}
781 /// std::deque-like containers: All iterators, including the past-the-end
782 /// iterator, are invalidated.
784 void deque_emplace_front(std::deque<int> &D, int n) {
785 auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
787 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
788 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
790 D.emplace_front(n);
792 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
793 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
794 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
797 /// std::forward_list-like containers: No iterators are invalidated.
799 void forward_list_emplace_front(std::forward_list<int> &FL, int n) {
800 auto i0 = FL.cbegin(), i1 = FL.cend();
802 clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
803 clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
805 FL.emplace_front(n);
807 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
808 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
810 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
811 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.end(){{$}}}}
814 /// pop_front()
816 /// - Design decision: shrinks containers to the ->RIGHT-> (i.e. the first
817 /// position of the container is incremented).
819 /// - Iterator invalidation rules depend the container type.
821 /// std::list-like containers: Iterators to the first element are invalidated.
823 void list_pop_front(std::list<int> &L, int n) {
824 auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend();
826 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
827 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
829 L.pop_front();
831 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
832 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
833 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
835 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.begin() + 1{{$}}}}
836 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
839 /// std::deque-like containers: Iterators to the first element are invalidated.
840 /// Other iterators are not affected.
842 void deque_pop_front(std::deque<int> &D, int n) {
843 auto i0 = D.cbegin(), i1 = ++D.cbegin(), i2 = D.cend();
845 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
846 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
848 D.pop_front();
850 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
851 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
852 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
854 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$D.begin() + 1{{$}}}}
855 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$D.end(){{$}}}}
858 /// std::forward_list-like containers: Iterators to the first element are
859 /// invalidated.
861 void forward_list_pop_front(std::list<int> &FL, int n) {
862 auto i0 = FL.cbegin(), i1 = ++FL.cbegin(), i2 = FL.cend();
864 clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
865 clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
867 FL.pop_front();
869 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
870 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
871 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
873 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.begin() + 1{{$}}}}
874 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.end(){{$}}}}
877 /// insert()
879 /// - Design decision: shifts positions to the <-LEFT<- (i.e. all iterator
880 /// ahead of the insertion point are decremented; if the
881 /// relation between the insertion point and the first
882 /// position of the container is known, the first position
883 /// of the container is also decremented).
885 /// - Iterator invalidation rules depend the container type.
887 /// std::list-like containers: No iterators are invalidated.
889 void list_insert_begin(std::list<int> &L, int n) {
890 auto i0 = L.cbegin(), i1 = L.cend();
892 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
893 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
895 auto i2 = L.insert(i0, n);
897 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
898 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
900 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
901 // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $L.begin() - 1
902 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end(){{$}}}}
905 void list_insert_behind_begin(std::list<int> &L, int n) {
906 auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend();
908 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
909 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
911 auto i3 = L.insert(i1, n);
913 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
914 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
915 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
917 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}} FIXME: Should be $L.begin() - 1
918 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.begin() + 1{{$}}}}
919 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.begin()
920 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
923 template <typename Iter> Iter return_any_iterator(const Iter &It);
925 void list_insert_unknown(std::list<int> &L, int n) {
926 auto i0 = L.cbegin(), i1 = return_any_iterator(L.cbegin()), i2 = L.cend();
928 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
929 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
930 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
932 auto i3 = L.insert(i1, n);
934 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
935 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
936 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
938 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
939 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$i1{{$}}}}
940 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i - 1
941 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
944 void list_insert_ahead_of_end(std::list<int> &L, int n) {
945 auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
947 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
948 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
950 auto i3 = L.insert(i1, n);
952 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
953 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
954 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
956 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
957 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}}
958 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
959 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end() - 2
962 void list_insert_end(std::list<int> &L, int n) {
963 auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
965 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
966 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
968 auto i3 = L.insert(i2, n);
970 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
971 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
972 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
974 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
975 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}} FIXME: should be $L.end() - 2
976 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
977 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end() - 1
980 /// std::vector-like containers: Only the iterators before the insertion point
981 /// remain valid. The past-the-end iterator is also
982 /// invalidated.
984 void vector_insert_begin(std::vector<int> &V, int n) {
985 auto i0 = V.cbegin(), i1 = V.cend();
987 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
988 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
990 auto i2 = V.insert(i0, n);
992 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
993 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
995 // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $V.begin() - 1
998 void vector_insert_behind_begin(std::vector<int> &V, int n) {
999 auto i0 = V.cbegin(), i1 = ++V.cbegin(), i2 = V.cend();
1001 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1002 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1004 auto i3 = V.insert(i1, n);
1006 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1007 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1008 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1010 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}} FIXME: Should be $V.begin() - 1
1011 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); // FIXME: expect -warning $V.begin()
1014 void vector_insert_unknown(std::vector<int> &V, int n) {
1015 auto i0 = V.cbegin(), i1 = return_any_iterator(V.cbegin()), i2 = V.cend();
1017 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1018 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1019 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1021 auto i3 = V.insert(i1, n);
1023 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1024 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1025 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1027 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1028 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expecte warning $i1 - 1
1031 void vector_insert_ahead_of_end(std::vector<int> &V, int n) {
1032 auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
1034 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1035 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1037 auto i3 = V.insert(i1, n);
1039 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1040 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1041 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1043 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1044 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.end() - 2
1047 void vector_insert_end(std::vector<int> &V, int n) {
1048 auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
1050 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1051 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1053 auto i3 = V.insert(i2, n);
1055 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1056 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1057 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1059 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1060 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V.end() - 1{{$}}}} FIXME: Should be $V.end() - 2
1061 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.end() - 1
1064 /// std::deque-like containers: All iterators, including the past-the-end
1065 /// iterator, are invalidated.
1067 void deque_insert_begin(std::deque<int> &D, int n) {
1068 auto i0 = D.cbegin(), i1 = D.cend();
1070 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1071 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1073 auto i2 = D.insert(i0, n);
1075 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1076 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1078 // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $D.begin() - 1
1081 void deque_insert_behind_begin(std::deque<int> &D, int n) {
1082 auto i0 = D.cbegin(), i1 = ++D.cbegin(), i2 = D.cend();
1084 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1085 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1087 auto i3 = D.insert(i1, n);
1089 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1090 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1091 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1093 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.begin() - 1
1096 void deque_insert_unknown(std::deque<int> &D, int n) {
1097 auto i0 = D.cbegin(), i1 = return_any_iterator(D.cbegin()), i2 = D.cend();
1099 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1100 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1101 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1103 auto i3 = D.insert(i1, n);
1105 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1106 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1107 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1109 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 - 1
1112 void deque_insert_ahead_of_end(std::deque<int> &D, int n) {
1113 auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
1115 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1116 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1118 auto i3 = D.insert(i1, n);
1120 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1121 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1122 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1124 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 2
1127 void deque_insert_end(std::deque<int> &D, int n) {
1128 auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
1130 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1131 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1133 auto i3 = D.insert(i2, n);
1135 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1136 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1137 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1139 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 1
1142 /// insert_after() [std::forward_list-like containers]
1144 /// - Design decision: shifts positions to the ->RIGHT-> (i.e. all iterator
1145 /// ahead of the insertion point are incremented; if the
1146 /// relation between the insertion point and the past-the-end
1147 /// position of the container is known, the first position of
1148 /// the container is also incremented).
1150 /// - No iterators are invalidated.
1152 void forward_list_insert_after_begin(std::forward_list<int> &FL, int n) {
1153 auto i0 = FL.cbegin(), i1 = FL.cend();
1155 clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1156 clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1158 auto i2 = FL.insert_after(i0, n);
1160 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1161 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1163 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1164 // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $FL.begin() + 1
1165 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.end(){{$}}}}
1168 void forward_list_insert_after_behind_begin(std::forward_list<int> &FL, int n) {
1169 auto i0 = FL.cbegin(), i1 = ++FL.cbegin(), i2 = FL.cend();
1171 clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1172 clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1174 auto i3 = FL.insert_after(i1, n);
1176 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1177 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1178 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1180 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1181 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.begin() + 1{{$}}}}
1182 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $FL.begin() + 2
1183 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.end(){{$}}}}
1186 void forward_list_insert_after_unknown(std::forward_list<int> &FL, int n) {
1187 auto i0 = FL.cbegin(), i1 = return_any_iterator(FL.cbegin()), i2 = FL.cend();
1189 clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1190 clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1191 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1193 auto i3 = FL.insert_after(i1, n);
1195 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1196 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1197 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1199 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1200 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$i1{{$}}}}
1201 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 + 1
1202 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.end(){{$}}}}
1205 /// emplace()
1207 /// - Design decision: shifts positions to the <-LEFT<- (i.e. all iterator
1208 /// ahead of the emplacement point are decremented; if the
1209 /// relation between the emplacement point and the first
1210 /// position of the container is known, the first position
1211 /// of the container is also decremented).
1213 /// - Iterator invalidation rules depend the container type.
1215 /// std::list-like containers: No iterators are invalidated.
1217 void list_emplace_begin(std::list<int> &L, int n) {
1218 auto i0 = L.cbegin(), i1 = L.cend();
1220 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1221 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1223 auto i2 = L.emplace(i0, n);
1225 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1226 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1228 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1229 // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $L.begin() - 1
1230 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end(){{$}}}}
1233 void list_emplace_behind_begin(std::list<int> &L, int n) {
1234 auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend();
1236 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1237 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1239 auto i3 = L.emplace(i1, n);
1241 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1242 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1243 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1245 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}} FIXME: Should be $L.begin() - 1
1246 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.begin() + 1{{$}}}}
1247 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.begin()
1248 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1251 template <typename Iter> Iter return_any_iterator(const Iter &It);
1253 void list_emplace_unknown(std::list<int> &L, int n) {
1254 auto i0 = L.cbegin(), i1 = return_any_iterator(L.cbegin()), i2 = L.cend();
1256 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1257 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1258 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1260 auto i3 = L.emplace(i1, n);
1262 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1263 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1264 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1266 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1267 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$i1{{$}}}}
1268 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i - 1
1269 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1272 void list_emplace_ahead_of_end(std::list<int> &L, int n) {
1273 auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
1275 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1276 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1278 auto i3 = L.emplace(i1, n);
1280 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1281 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1282 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1284 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1285 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}}
1286 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1287 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end() - 2
1290 void list_emplace_end(std::list<int> &L, int n) {
1291 auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
1293 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1294 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1296 auto i3 = L.emplace(i2, n);
1298 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1299 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1300 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1302 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1303 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}} FIXME: should be $L.end() - 2
1304 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1305 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end() - 1
1308 /// std::vector-like containers: Only the iterators before the emplacement point
1309 /// remain valid. The past-the-end iterator is also
1310 /// invalidated.
1312 void vector_emplace_begin(std::vector<int> &V, int n) {
1313 auto i0 = V.cbegin(), i1 = V.cend();
1315 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1316 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1318 auto i2 = V.emplace(i0, n);
1320 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1321 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1322 // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $V.begin() - 1
1325 void vector_emplace_behind_begin(std::vector<int> &V, int n) {
1326 auto i0 = V.cbegin(), i1 = ++V.cbegin(), i2 = V.cend();
1328 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1329 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1331 auto i3 = V.emplace(i1, n);
1333 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1334 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1335 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1337 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}} FIXME: Should be $V.begin() - 1
1338 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); // FIXME: expect -warning $V.begin()
1341 void vector_emplace_unknown(std::vector<int> &V, int n) {
1342 auto i0 = V.cbegin(), i1 = return_any_iterator(V.cbegin()), i2 = V.cend();
1344 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1345 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1346 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1348 auto i3 = V.emplace(i1, n);
1350 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1351 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1352 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1354 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1355 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expecte warning $i1 - 1
1358 void vector_emplace_ahead_of_end(std::vector<int> &V, int n) {
1359 auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
1361 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1362 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1364 auto i3 = V.emplace(i1, n);
1366 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1367 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1368 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1370 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1371 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.end() - 2
1374 void vector_emplace_end(std::vector<int> &V, int n) {
1375 auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
1377 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1378 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1380 auto i3 = V.emplace(i2, n);
1382 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1383 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1384 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1386 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1387 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V.end() - 1{{$}}}} FIXME: Should be $V.end() - 2
1388 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.end() - 1
1391 /// std::deque-like containers: All iterators, including the past-the-end
1392 /// iterator, are invalidated.
1394 void deque_emplace_begin(std::deque<int> &D, int n) {
1395 auto i0 = D.cbegin(), i1 = D.cend();
1397 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1398 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1400 auto i2 = D.emplace(i0, n);
1402 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1403 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1404 // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $D.begin() - 1
1407 void deque_emplace_behind_begin(std::deque<int> &D, int n) {
1408 auto i0 = D.cbegin(), i1 = ++D.cbegin(), i2 = D.cend();
1410 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1411 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1413 auto i3 = D.emplace(i1, n);
1415 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1416 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1417 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1418 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.begin() - 1
1421 void deque_emplace_unknown(std::deque<int> &D, int n) {
1422 auto i0 = D.cbegin(), i1 = return_any_iterator(D.cbegin()), i2 = D.cend();
1424 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1425 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1426 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1428 auto i3 = D.emplace(i1, n);
1430 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1431 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1432 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1434 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 - 1
1437 void deque_emplace_ahead_of_end(std::deque<int> &D, int n) {
1438 auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
1440 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1441 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1443 auto i3 = D.emplace(i1, n);
1445 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1446 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1447 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1449 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 2
1452 void deque_emplace_end(std::deque<int> &D, int n) {
1453 auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
1455 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1456 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1458 auto i3 = D.emplace(i2, n);
1460 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1461 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1462 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1464 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 1
1467 /// emplace_after() [std::forward_list-like containers]
1469 /// - Design decision: shifts positions to the ->RIGHT-> (i.e. all iterator
1470 /// ahead of the emplacement point are incremented; if the
1471 /// relation between the emplacement point and the
1472 /// past-the-end position of the container is known, the
1473 /// first position of the container is also incremented).
1475 /// - No iterators are invalidated.
1477 void forward_list_emplace_after_begin(std::forward_list<int> &FL, int n) {
1478 auto i0 = FL.cbegin(), i1 = FL.cend();
1480 clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1481 clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1483 auto i2 = FL.emplace_after(i0, n);
1485 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1486 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1488 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1489 // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $FL.begin() + 1
1490 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.end(){{$}}}}
1493 void forward_list_emplace_after_behind_begin(std::forward_list<int> &FL,
1494 int n) {
1495 auto i0 = FL.cbegin(), i1 = ++FL.cbegin(), i2 = FL.cend();
1497 clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1498 clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1500 auto i3 = FL.emplace_after(i1, n);
1502 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1503 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1504 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1506 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1507 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$FL.begin() + 1{{$}}}}
1508 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $FL.begin() + 2
1509 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.end(){{$}}}}
1512 void forward_list_emplace_after_unknown(std::forward_list<int> &FL, int n) {
1513 auto i0 = FL.cbegin(), i1 = return_any_iterator(FL.cbegin()), i2 = FL.cend();
1515 clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1516 clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1517 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1519 auto i3 = FL.emplace_after(i1, n);
1521 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1522 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1523 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1525 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1526 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$i1{{$}}}}
1527 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 + 1
1528 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.end(){{$}}}}
1531 /// erase()
1533 /// - Design decision: shifts positions to the ->RIGHT-> (i.e. all iterator
1534 /// ahead of the ereased element are incremented; if the
1535 /// relation between the position of the erased element
1536 /// and the first position of the container is known, the
1537 /// first position of the container is also incremented).
1539 /// - Iterator invalidation rules depend the container type.
1541 /// std::list-like containers: Iterators to the erased element are invalidated.
1542 /// Other iterators are not affected.
1544 void list_erase_begin(std::list<int> &L) {
1545 auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend();
1547 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1548 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1550 auto i3 = L.erase(i0);
1552 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1553 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1554 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1556 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.begin() + 1{{$}}}}
1557 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.begin() + 1
1558 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1561 void list_erase_behind_begin(std::list<int> &L, int n) {
1562 auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend();
1564 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1565 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1567 auto i3 = L.erase(i1);
1569 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1570 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1571 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1573 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}} FIXME: Should be $L.begin() + 1
1574 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.begin() + 2
1575 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1578 void list_erase_unknown(std::list<int> &L) {
1579 auto i0 = L.cbegin(), i1 = return_any_iterator(L.cbegin()), i2 = L.cend();
1581 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1582 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1583 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1585 auto i3 = L.erase(i1);
1587 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1588 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1589 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1591 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1592 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 + 1
1593 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1596 void list_erase_ahead_of_end(std::list<int> &L) {
1597 auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend();
1599 clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
1600 clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
1602 auto i3 = L.erase(i1);
1604 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1605 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1606 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1608 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
1609 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}}
1610 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end()
1613 /// std::vector-like containers: Invalidates iterators at or after the point of
1614 /// the erase, including the past-the-end iterator.
1616 void vector_erase_begin(std::vector<int> &V) {
1617 auto i0 = V.cbegin(), i1 = ++V.cbegin(), i2 = V.cend();
1619 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1620 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1622 auto i3 = V.erase(i0);
1624 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1625 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1626 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1628 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.begin() + 1
1631 void vector_erase_behind_begin(std::vector<int> &V, int n) {
1632 auto i0 = V.cbegin(), i1 = ++V.cbegin(), i2 = V.cend();
1634 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1635 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1637 auto i3 = V.erase(i1);
1639 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1640 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1641 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1643 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}} FIXME: Should be $V.begin() + 1
1644 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.begin() + 2
1647 void vector_erase_unknown(std::vector<int> &V) {
1648 auto i0 = V.cbegin(), i1 = return_any_iterator(V.cbegin()), i2 = V.cend();
1650 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1651 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1652 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1654 auto i3 = V.erase(i1);
1656 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1657 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1658 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1660 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1661 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 + 1
1664 void vector_erase_ahead_of_end(std::vector<int> &V) {
1665 auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend();
1667 clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
1668 clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
1670 auto i3 = V.erase(i1);
1672 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1673 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1674 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1676 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}}
1677 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $V.end()
1680 /// std::deque-like containers: All iterators are invalidated, unless the erased
1681 /// element is at the end or the beginning of the
1682 /// container, in which case only the iterators to
1683 /// the erased element are invalidated. The
1684 /// past-the-end iterator is also invalidated unless
1685 /// the erased element is at the beginning of the
1686 /// container and the last element is not erased.
1688 void deque_erase_begin(std::deque<int> &D) {
1689 auto i0 = D.cbegin(), i1 = ++D.cbegin(), i2 = D.cend();
1691 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1692 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1694 auto i3 = D.erase(i0);
1696 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1697 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1698 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1700 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.begin() + 1
1703 void deque_erase_behind_begin(std::deque<int> &D, int n) {
1704 auto i0 = D.cbegin(), i1 = ++D.cbegin(), i2 = D.cend();
1706 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1707 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1709 auto i3 = D.erase(i1);
1711 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1712 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1713 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1715 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.begin() + 2
1718 void deque_erase_unknown(std::deque<int> &D) {
1719 auto i0 = D.cbegin(), i1 = return_any_iterator(D.cbegin()), i2 = D.cend();
1721 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1722 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1723 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1725 auto i3 = D.erase(i1);
1727 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1728 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1729 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1731 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $i1 + 1
1734 void deque_erase_ahead_of_end(std::deque<int> &D) {
1735 auto i0 = D.cbegin(), i1 = --D.cend(), i2 = D.cend();
1737 clang_analyzer_denote(clang_analyzer_container_begin(D), "$D.begin()");
1738 clang_analyzer_denote(clang_analyzer_container_end(D), "$D.end()");
1740 auto i3 = D.erase(i1);
1742 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{FALSE}}
1743 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1744 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1746 // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end()
1749 /// erase_after() [std::forward_list-like containers]
1751 /// - Design decision: shifts positions to the <-LEFT<- (i.e. all iterator
1752 /// begind of the ereased element are decremented; if the
1753 /// relation between the position of the erased element
1754 /// and the past-the-end position of the container is known,
1755 /// the past-the-end position of the container is also
1756 /// decremented).
1758 /// - Iterators to the erased element are invalidated. Other iterators are not
1759 /// affected.
1762 void forward_list_erase_after_begin(std::forward_list<int> &FL) {
1763 auto i0 = FL.cbegin(), i1 = ++FL.cbegin(), i2 = i1, i3 = FL.cend();
1764 ++i2;
1766 clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1767 clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1769 auto i4 = FL.erase_after(i0);
1771 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1772 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}}
1773 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}}
1774 clang_analyzer_eval(clang_analyzer_iterator_validity(i3)); //expected-warning{{TRUE}}
1776 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1777 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$FL.begin() + 2{{$}}}} FIXME: Should be $FL.begin() + 1
1778 // clang_analyzer_express(clang_analyzer_iterator_position(i4)); FIXME: expect warning $FL.begin() + 1
1779 clang_analyzer_express(clang_analyzer_iterator_position(i3)); // expected-warning-re {{$FL.end(){{$}}}}
1782 void forward_list_erase_after_unknown(std::forward_list<int> &FL) {
1783 auto i0 = FL.cbegin(), i1 = return_any_iterator(FL.cbegin()), i2 = i1,
1784 i3 = i1, i4 = FL.cend();
1785 ++i2;
1786 ++i3;
1787 ++i3;
1789 clang_analyzer_denote(clang_analyzer_container_begin(FL), "$FL.begin()");
1790 clang_analyzer_denote(clang_analyzer_container_end(FL), "$FL.end()");
1791 clang_analyzer_denote(clang_analyzer_iterator_position(i1), "$i1");
1793 auto i5 = FL.erase_after(i1);
1795 clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
1796 clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
1797 clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}}
1798 clang_analyzer_eval(clang_analyzer_iterator_validity(i3)); //expected-warning{{TRUE}}
1799 clang_analyzer_eval(clang_analyzer_iterator_validity(i4)); //expected-warning{{TRUE}}
1801 clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$FL.begin(){{$}}}}
1802 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$i1{{$}}}}
1803 clang_analyzer_express(clang_analyzer_iterator_position(i3)); // expected-warning-re {{$i1 + 2{{$}}}} FIXME: Should be $i1 + 1
1804 // clang_analyzer_express(clang_analyzer_iterator_position(i5)); FIXME: expect warning $i1 + 1
1805 clang_analyzer_express(clang_analyzer_iterator_position(i4)); // expected-warning-re {{$FL.end(){{$}}}}
1808 struct simple_iterator_base {
1809 simple_iterator_base();
1810 simple_iterator_base(const simple_iterator_base& rhs);
1811 simple_iterator_base &operator=(const simple_iterator_base& rhs);
1812 virtual ~simple_iterator_base();
1813 bool friend operator==(const simple_iterator_base &lhs,
1814 const simple_iterator_base &rhs);
1815 bool friend operator!=(const simple_iterator_base &lhs,
1816 const simple_iterator_base &rhs);
1817 private:
1818 int *ptr;
1821 struct simple_derived_iterator: public simple_iterator_base {
1822 int& operator*();
1823 int* operator->();
1824 simple_iterator_base &operator++();
1825 simple_iterator_base operator++(int);
1826 simple_iterator_base &operator--();
1827 simple_iterator_base operator--(int);
1830 struct simple_container {
1831 typedef simple_derived_iterator iterator;
1833 iterator begin();
1834 iterator end();
1837 void good_derived(simple_container c) {
1838 auto i0 = c.end();
1840 if (i0 != c.end()) {
1841 clang_analyzer_warnIfReached();
1845 void iter_diff(std::vector<int> &V) {
1846 auto i0 = V.begin(), i1 = V.end();
1847 ptrdiff_t len = i1 - i0; // no-crash
1850 void deferred_assumption(std::vector<int> &V, int e) {
1851 const auto first = V.begin();
1852 const auto comp1 = (first != V.end()), comp2 = (first == V.end());
1853 if (comp1) {
1854 clang_analyzer_eval(clang_analyzer_container_end(V) ==
1855 clang_analyzer_iterator_position(first)); // expected-warning@-1{{FALSE}}
1859 void loop(std::vector<int> &V, int e) {
1860 auto start = V.begin();
1861 while (true) {
1862 auto item = std::find(start, V.end(), e);
1863 if (item == V.end())
1864 break;
1866 clang_analyzer_eval(clang_analyzer_container_end(V) ==
1867 clang_analyzer_iterator_position(item)); // expected-warning@-1{{FALSE}}
1871 template <typename InputIterator, typename T>
1872 InputIterator nonStdFind(InputIterator first, InputIterator last,
1873 const T &val) {
1874 for (auto i = first; i != last; ++i) {
1875 if (*i == val) {
1876 return i;
1879 return last;
1882 void non_std_find(std::vector<int> &V, int e) {
1883 auto first = nonStdFind(V.begin(), V.end(), e);
1884 clang_analyzer_eval(clang_analyzer_container_end(V) ==
1885 clang_analyzer_iterator_position(first)); // expected-warning@-1{{FALSE}} expected-warning@-1{{TRUE}}
1886 if (V.end() != first) {
1887 clang_analyzer_eval(clang_analyzer_container_end(V) ==
1888 clang_analyzer_iterator_position(first)); // expected-warning@-1{{FALSE}}
1892 template<typename T>
1893 struct cont_with_ptr_iterator {
1894 typedef T* iterator;
1895 T* begin() const;
1896 T* end() const;
1899 void begin_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
1900 auto i = c.begin();
1902 clang_analyzer_eval(clang_analyzer_iterator_container(i) == &c); // expected-warning{{TRUE}}
1903 clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
1904 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.begin()}}
1906 if (i != c.begin()) {
1907 clang_analyzer_warnIfReached();
1911 void prefix_increment_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
1912 auto i = c.begin();
1914 clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
1916 auto j = ++i;
1918 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.begin() + 1}}
1919 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning{{$c.begin() + 1}}
1922 void prefix_decrement_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
1923 auto i = c.end();
1925 clang_analyzer_denote(clang_analyzer_container_end(c), "$c.end()");
1927 auto j = --i;
1929 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.end() - 1}}
1930 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning{{$c.end() - 1}}
1933 void postfix_increment_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
1934 auto i = c.begin();
1936 clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
1938 auto j = i++;
1940 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.begin() + 1}}
1941 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning{{$c.begin()}}
1944 void postfix_decrement_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
1945 auto i = c.end();
1947 clang_analyzer_denote(clang_analyzer_container_end(c), "$c.end()");
1949 auto j = i--;
1951 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.end() - 1}}
1952 clang_analyzer_express(clang_analyzer_iterator_position(j)); // expected-warning{{$c.end()}}
1955 void plus_equal_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
1956 auto i = c.begin();
1958 clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
1960 i += 2;
1962 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.begin() + 2}}
1965 void minus_equal_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
1966 auto i = c.end();
1968 clang_analyzer_denote(clang_analyzer_container_end(c), "$c.end()");
1970 i -= 2;
1972 clang_analyzer_express(clang_analyzer_iterator_position(i)); // expected-warning{{$c.end() - 2}}
1975 void minus_equal_ptr_iterator_variable(const cont_with_ptr_iterator<int> &c,
1976 int n) {
1977 auto i = c.end();
1979 i -= n; // no-crash
1982 void plus_lhs_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
1983 auto i1 = c.begin();
1985 clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
1987 auto i2 = i1 + 2;
1989 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &c); // expected-warning{{TRUE}}
1990 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$c.begin()}}
1991 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$c.begin() + 2}}
1994 void plus_rhs_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
1995 auto i1 = c.begin();
1997 clang_analyzer_denote(clang_analyzer_container_begin(c), "$c.begin()");
1999 auto i2 = 2 + i1;
2001 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &c); // expected-warning{{TRUE}}
2002 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$c.begin()}}
2003 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$c.begin() + 2}}
2006 void minus_ptr_iterator(const cont_with_ptr_iterator<int> &c) {
2007 auto i1 = c.end();
2009 clang_analyzer_denote(clang_analyzer_container_end(c), "$c.end()");
2011 auto i2 = i1 - 2;
2013 clang_analyzer_eval(clang_analyzer_iterator_container(i2) == &c); // expected-warning{{TRUE}}
2014 clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$c.end()}}
2015 clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$c.end() - 2}}
2018 void ptr_iter_diff(cont_with_ptr_iterator<int> &c) {
2019 auto i0 = c.begin(), i1 = c.end();
2020 ptrdiff_t len = i1 - i0; // no-crash
2023 void ptr_iter_cmp_nullptr(cont_with_ptr_iterator<int> &c) {
2024 auto i0 = c.begin();
2025 if (i0 != nullptr) // no-crash
2026 ++i0;
2029 void clang_analyzer_printState();
2031 void print_state(std::vector<int> &V) {
2032 const auto i0 = V.cbegin();
2033 clang_analyzer_printState();
2035 // CHECK: "checker_messages": [
2036 // CHECK: { "checker": "alpha.cplusplus.IteratorModeling", "messages": [
2037 // CHECK-NEXT: "Iterator Positions :",
2038 // CHECK-NEXT: "i0 : Valid ; Container == SymRegion{reg_$[[#]]<std::vector<int> & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
2039 // CHECK-NEXT: ]}
2041 *i0;
2042 const auto i1 = V.cend();
2043 clang_analyzer_printState();
2045 // CHECK: "checker_messages": [
2046 // CHECK: { "checker": "alpha.cplusplus.IteratorModeling", "messages": [
2047 // CHECK-NEXT: "Iterator Positions :",
2048 // CHECK-NEXT: "i1 : Valid ; Container == SymRegion{reg_$[[#]]<std::vector<int> & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
2049 // CHECK-NEXT: ]}
2051 *i1;