vector<int> vec;
...
for(auto it = vec.begin(); it != vec.end();) {
...
do {
...
if(++it == vec.end()) break;
} while(*it == 123);
...
}
warning: Either the condition 'it!=prev.end()' is redundant or there is
possible dereference of an invalid iterator: it. [derefInvalidIteratorRedundantCheck] } while(it == 123);
^note: Assuming that condition 'it!=prev.end()' is not
redundant for(auto it = vec.begin(); it != vec.end();) {
^note: Dereference of an invalid iterator
} while(it == 123); ^
This seems to be a false positive:
(using 2.19.0)
warning: Either the condition 'it!=prev.end()' is redundant or there is
possible dereference of an invalid iterator: it.
[derefInvalidIteratorRedundantCheck] } while(it == 123);
^note: Assuming that condition 'it!=prev.end()' is not
redundant for(auto it = vec.begin(); it != vec.end();) {
^note: Dereference of an invalid iterator
} while(it == 123); ^
-Doug
Last edit: DougCube 5 days ago
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14443