[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 17 09:03:11 PDT 2025


================
@@ -1139,6 +1289,271 @@ void deque_insert_end(std::deque<int> &D, int n) {
   // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 1
 }
 
+/// insert_range()
+///
+/// - Design decision: shifts positions to the <-LEFT<- (i.e. all iterator
+///                    ahead of the insertion point are decremented; if the
+///                    relation between the insertion point and the first
+///                    position of the container is known, the first position
+///                    of the container is also decremented).
+///
+/// - Iterator invalidation rules depend the container type.
+
+/// std::list-like containers: No iterators are invalidated.
+
+void list_insert_range_begin(std::list<int> &L, std::vector<int>& vec) {
+  auto i0 = L.cbegin(), i1 = L.cend();
+
+  clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
+  clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
+
+  auto i2 = L.insert_range(i0, vec);
+
+  clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}}
+  clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}}
+
+  clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}}
+  // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $L.begin() - 1
----------------
steakhal wrote:

Why is this line disabled? We could (and should) expect the actual output; and put a FIXME there if it's actually not what is desired.

https://github.com/llvm/llvm-project/pull/129719


More information about the cfe-commits mailing list