Hi, I found a false negative regarding the rule invalidContainer.
invalidContainer
Cppcheck misses the use of an invalidated iterator when the vector is accessed through a reference alias.
#include <vector> void f() { std::vector<int> items{1, 2, 3}; std::vector<int> &values = items; auto iter = values.begin(); values.erase(iter); ++iter; }
Cppcheck does not report invalidContainer. Removing the reference declaration and replacing values with items produces the warning.
values
items
Cppcheck should report the use of the invalidated iterator with or without the reference alias.
The issue was reproduced with:
cppcheck --output-format=xmlv2 --enable=all container_reference.cpp
Version: 2.21.0
See https://trac.cppcheck.net/ticket/14677
Log in to post a comment.
Hi, I found a false negative regarding the rule
invalidContainer.Cppcheck misses the use of an invalidated iterator when the vector is accessed through a reference alias.
Actual result
Cppcheck does not report
invalidContainer. Removing the reference declaration and replacingvalueswithitemsproduces the warning.Expected result
Cppcheck should report the use of the invalidated iterator with or without the reference alias.
Verification
The issue was reproduced with:
Version: 2.21.0
See https://trac.cppcheck.net/ticket/14677