It seems that cppcheck does not always take into account that variables can be accessed via pointer. Note that the error goes away if the 'Map' array only consists of one element.
intmain() {
boolb0{}, b1{};struct {
bool*pb;intval;
}
Map[] = { {&b0, 0}, {&b1, 1} };b0=true; // style: Variable 'b0' is assigned a value that is never used.for(auto&m : Map)if(m.pb&&*m.pb)m.val=1;return0;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It seems that cppcheck does not always take into account that variables can be accessed via pointer. Note that the error goes away if the 'Map' array only consists of one element.
Thanks! I created https://trac.cppcheck.net/ticket/9828
A different false positive, where the decremented value is used immediately in the comparison:
There is no FP anymore for this
Thanks! I can reproduce. I created https://trac.cppcheck.net/ticket/9901