The following code will generate a false positive for knownConditionTrueFalse with cppcheck 2.18
#include <vector> void foo(const std::vector<int> &bar) { for(const int &b : bar) { for(const int &c : bar) { if (&c == &b) continue; } } }
cppcheck --enable=style test.cpp
test.cpp:9:14: style: The comparison '&c == &b' is always true because '&c' and '&b' represent the same value. [knownConditionTrueFalse] if (&c == &b) ^ test.cpp:7:24: note: 'c' is assigned value 'bar' here. for(const int &c : bar) ^ test.cpp:5:22: note: 'b' is assigned value 'bar' here. for(const int &b : bar) ^ test.cpp:9:14: note: The comparison '&c == &b' is always true because '&c' and '&b' represent the same value. if (&c == &b)
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14193
Might be worth mentioning that if &c == &b is replaced with c < 0 && b > 0, it triggers:
&c == &b
c < 0 && b > 0
Logical conjunction always evaluates to false: c < 0 && b > 0. [incorrectLogicOperator]
Log in to post a comment.
The following code will generate a false positive for knownConditionTrueFalse with cppcheck 2.18
cppcheck --enable=style test.cpp
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14193
Might be worth mentioning that if
&c == &b
is replaced withc < 0 && b > 0
, it triggers: