1 // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=false %s -verify
2 // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus,alpha.cplusplus.InvalidatedIterator -analyzer-config aggressive-binary-operation-simplification=true -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify
4 #include "Inputs/system-header-simulator-cxx.h"
6 void clang_analyzer_warnIfReached();
8 void normal_dereference(std::vector
<int> &V
) {
13 void invalidated_dereference(std::vector
<int> &V
) {
16 *i
; // expected-warning{{Invalidated iterator accessed}}
19 void normal_prefix_increment(std::vector
<int> &V
) {
24 void invalidated_prefix_increment(std::vector
<int> &V
) {
27 ++i
; // expected-warning{{Invalidated iterator accessed}}
30 void normal_prefix_decrement(std::vector
<int> &V
) {
31 auto i
= ++V
.cbegin();
35 void invalidated_prefix_decrement(std::vector
<int> &V
) {
36 auto i
= ++V
.cbegin();
38 --i
; // expected-warning{{Invalidated iterator accessed}}
41 void normal_postfix_increment(std::vector
<int> &V
) {
46 void invalidated_postfix_increment(std::vector
<int> &V
) {
49 i
++; // expected-warning{{Invalidated iterator accessed}}
52 void normal_postfix_decrement(std::vector
<int> &V
) {
53 auto i
= ++V
.cbegin();
57 void invalidated_postfix_decrement(std::vector
<int> &V
) {
58 auto i
= ++V
.cbegin();
60 i
--; // expected-warning{{Invalidated iterator accessed}}
63 void normal_increment_by_2(std::vector
<int> &V
) {
68 void invalidated_increment_by_2(std::vector
<int> &V
) {
71 i
+= 2; // expected-warning{{Invalidated iterator accessed}}
74 void normal_increment_by_2_copy(std::vector
<int> &V
) {
76 auto j
= i
+ 2; // no-warning
79 void invalidated_increment_by_2_copy(std::vector
<int> &V
) {
82 auto j
= i
+ 2; // expected-warning{{Invalidated iterator accessed}}
85 void normal_decrement_by_2(std::vector
<int> &V
) {
90 void invalidated_decrement_by_2(std::vector
<int> &V
) {
93 i
-= 2; // expected-warning{{Invalidated iterator accessed}}
96 void normal_decrement_by_2_copy(std::vector
<int> &V
) {
98 auto j
= i
- 2; // no-warning
101 void invalidated_decrement_by_2_copy(std::vector
<int> &V
) {
104 auto j
= i
- 2; // expected-warning{{Invalidated iterator accessed}}
107 void normal_subscript(std::vector
<int> &V
) {
112 void invalidated_subscript(std::vector
<int> &V
) {
115 i
[1]; // expected-warning{{Invalidated iterator accessed}}
118 void assignment(std::vector
<int> &V
) {
121 auto j
= V
.cbegin(); // no-warning
125 struct cont_with_ptr_iterator
{
128 T
&operator[](size_t);
129 void push_back(const T
&);
133 void invalidated_dereference_end_ptr_iterator(cont_with_ptr_iterator
<int> &C
) {
136 (void) *i
; // expected-warning{{Invalidated iterator accessed}}
139 void invalidated_prefix_increment_end_ptr_iterator(
140 cont_with_ptr_iterator
<int> &C
) {
143 ++i
; // expected-warning{{Invalidated iterator accessed}}
146 void invalidated_prefix_decrement_end_ptr_iterator(
147 cont_with_ptr_iterator
<int> &C
) {
148 auto i
= C
.begin() + 1;
150 --i
; // expected-warning{{Invalidated iterator accessed}}
153 void invalidated_postfix_increment_end_ptr_iterator(
154 cont_with_ptr_iterator
<int> &C
) {
157 i
++; // expected-warning{{Invalidated iterator accessed}}
160 void invalidated_postfix_decrement_end_ptr_iterator(
161 cont_with_ptr_iterator
<int> &C
) {
162 auto i
= C
.begin() + 1;
164 i
--; // expected-warning{{Invalidated iterator accessed}}
167 void invalidated_increment_by_2_end_ptr_iterator(
168 cont_with_ptr_iterator
<int> &C
) {
171 i
+= 2; // expected-warning{{Invalidated iterator accessed}}
174 void invalidated_increment_by_2_copy_end_ptr_iterator(
175 cont_with_ptr_iterator
<int> &C
) {
178 auto j
= i
+ 2; // expected-warning{{Invalidated iterator accessed}}
181 void invalidated_decrement_by_2_end_ptr_iterator(
182 cont_with_ptr_iterator
<int> &C
) {
185 i
-= 2; // expected-warning{{Invalidated iterator accessed}}
188 void invalidated_decrement_by_2_copy_end_ptr_iterator(
189 cont_with_ptr_iterator
<int> &C
) {
192 auto j
= i
- 2; // expected-warning{{Invalidated iterator accessed}}
195 void invalidated_subscript_end_ptr_iterator(cont_with_ptr_iterator
<int> &C
) {
198 (void) i
[1]; // expected-warning{{Invalidated iterator accessed}}