Hi, I found a false negative regarding the rule invalidContainer.
invalidContainer
Cppcheck misses the use of an invalidated vector iterator when the increment is written as an explicit operator call.
#include <vector> void f() { std::vector<int> items{1, 2, 3}; std::vector<int>::iterator iter; for (iter = items.begin(); iter != items.end(); iter.operator++()) { if (*iter == 2) items.erase(iter); } }
Cppcheck does not report invalidContainer. Replacing iter.operator++() with ++iter produces the warning. Using ++(iter) also misses the warning.
iter.operator++()
++iter
++(iter)
Cppcheck should report the use of the invalidated iterator regardless of the increment spelling.
The issue was reproduced with:
cppcheck --output-format=xmlv2 --enable=all invalid_iterator.cpp
Version: 2.21.0
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15076
Log in to post a comment.
Hi, I found a false negative regarding the rule
invalidContainer.Cppcheck misses the use of an invalidated vector iterator when the increment is written as an explicit operator call.
Actual result
Cppcheck does not report
invalidContainer. Replacingiter.operator++()with++iterproduces the warning. Using++(iter)also misses the warning.Expected result
Cppcheck should report the use of the invalidated iterator regardless of the increment spelling.
Verification
The issue was reproduced with:
Version: 2.21.0
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15076