================ @@ -635,6 +668,66 @@ void deque_emplace_back(std::deque<int> &D, int n) { clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}} } +/// append_range() +/// +/// - Design decision: extends containers to the ->RIGHT-> (i.e. the +/// past-the-end position of the container is incremented). +/// +/// - Iterator invalidation rules depend the container type. + +/// std::list-like containers: No iterators are invalidated. + +void list_append_range(std::list<int> &L, std::vector<int>& vec) { + auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()"); + + L.append_range(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_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$}}}} + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$}}}} + clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}} FIXME: Should be $L.end() + 1 +} + +/// std::vector-like containers: The past-the-end iterator is invalidated. + +void vector_append_range(std::vector<int> &V, std::vector<int>& vec) { + auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()"); + + V.emplace_back(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_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$}}}} + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V.end() - 1{{$}}}} ---------------- flovent wrote:
``` clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$}}}} ``` I add this in my local environment, it can pass the test, and it's missed in non-range version test function, so i think it's not intentional. https://github.com/llvm/llvm-project/pull/129719 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits