Yes, with that commit I got the FPs mentioned above. Maybe I missed to copy some parts of the file that trigger these FPs in the analysis, I'll look into that later.
Btw, I can't build the current head; for 7a6d7f7c2 I get:
lib/valueflow.cpp:2609:1: error: expected initializer before ‘Analyzer’
Analyzer::Result result{};
^~~~~~~~
lib/valueflow.cpp:2610:1: error: expected unqualified-id before ‘for’
for (const ValueFlow::Value& v : values)
^~~
lib/valueflow.cpp:2614:1: error: expected unqualified-id before ‘return’
return result;
^~~~~~
lib/valueflow.cpp:2615:1: error: expected declaration before ‘}’ token
}
^
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
./cppcheck --enable=all /home/user/Desktop/21-08-03.cpp
Checking /home/user/Desktop/21-08-03.cpp ...
/home/user/Desktop/21-08-03.cpp:6:18: style: Condition 'iter!=iterBegin' is always true [knownConditionTrueFalse]
if(iter != iterBegin)
^
/home/user/Desktop/21-08-03.cpp:4:22: note: iter is assigned 'iterBegin' here.
for (auto iter = iterBegin; iter != iterEnd; ++iter)
^
/home/user/Desktop/21-08-03.cpp:4:54: note: iter is incremented', new value is symbolic=iterBegin+1
for (auto iter = iterBegin; iter != iterEnd; ++iter)
^ /home/user/Desktop/21-08-03.cpp:6:18: note: Condition 'iter!=iterBegin' is always true
if(iter != iterBegin)
^
/home/user/Desktop/21-08-03.cpp:1:0: style: The function 'foo' is never used. [unusedFunction]
^
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
recently (f.e. as a result of the main branch commits of the last few days) a lot of false-positives showed up like this one:
(style) Condition 'i!=bodyStartIdx' is always true
This is only true for the first iteration.
I've seen findings like this also for other kind of loops.
Could you please check?
Thanks,
Martin
Second example:
--> (style) Condition 'sectIdx==linkSectionIdx' is always false
Maybe there should be a bailout for conditions where variables are involved which may be changed in each iteration of a loop?
Last edit: Martin 2021-08-03
I have seen similar FPs recently, but at least your examples seem to be fixed in head. Have you tried https://github.com/danmar/cppcheck/commit/c630be7f8f318194d7a1cb4dae274ee38bf785d9 or newer?
Yes, with that commit I got the FPs mentioned above. Maybe I missed to copy some parts of the file that trigger these FPs in the analysis, I'll look into that later.
Btw, I can't build the current head; for 7a6d7f7c2 I get:
lib/valueflow.cpp:2609:1: error: expected initializer before ‘Analyzer’
Analyzer::Result result{};
^~~~~~~~
lib/valueflow.cpp:2610:1: error: expected unqualified-id before ‘for’
for (const ValueFlow::Value& v : values)
^~~
lib/valueflow.cpp:2614:1: error: expected unqualified-id before ‘return’
return result;
^~~~~~
lib/valueflow.cpp:2615:1: error: expected declaration before ‘}’ token
}
^
I retried, with the latest commit I get the FP for a file containing only this code:
./cppcheck --enable=all /home/user/Desktop/21-08-03.cpp
Checking /home/user/Desktop/21-08-03.cpp ...
/home/user/Desktop/21-08-03.cpp:6:18: style: Condition 'iter!=iterBegin' is always true [knownConditionTrueFalse]
if(iter != iterBegin)
^
/home/user/Desktop/21-08-03.cpp:4:22: note: iter is assigned 'iterBegin' here.
for (auto iter = iterBegin; iter != iterEnd; ++iter)
^
/home/user/Desktop/21-08-03.cpp:4:54: note: iter is incremented', new value is symbolic=iterBegin+1
for (auto iter = iterBegin; iter != iterEnd; ++iter)
^
/home/user/Desktop/21-08-03.cpp:6:18: note: Condition 'iter!=iterBegin' is always true
if(iter != iterBegin)
^
/home/user/Desktop/21-08-03.cpp:1:0: style: The function 'foo' is never used. [unusedFunction]
^
Thanks for the example, ticket is here: https://trac.cppcheck.net/ticket/10395