Fix #14392 FN knownConditionTrueFalse (assigning function call result)#8118
Conversation
|
This looks like a true positive: https://github.com/danmar/cppcheck/blob/bf7697535163e9478ed1bd4b55c6a537e0d864fd/externals/tinyxml2/tinyxml2.cpp#L1133 |
|
|
I think that the original purpose of knownConditionTrueFalse was only to warn about redundant inner conditions meaning that it would be possible to remove code. For assignment and return statements it's not possible to remove code anymore. So it feels like the purpose is a bit different. I assume the intended fix will be to replace the expression with How does it sound to change the id also so ids are different for assignments, conditions, returns? please give me your honest opinion.. for personal reasons it would be better with separate ids; I have mapped knownConditionTrueFalse to Misra rules about invariant conditions so for that mapping to be more proper it would be better with separate ids. |
|
It is still possible to remove code in case of assignments and returns: if (alwaysTrue())
x = alwaysTrue() && doStuff(); // x = doStuff();if (alwaysTrue())
return alwaysTrue() || doStuff(); // return true;Without this change, we already warn for struct S {
bool g() const { return m; }
bool m{};
};
bool f(S s, int i) {
if (s.g()) {
const bool b = s.g() == true && i;
return b;
}
return false;
}and call Re: different IDs: I'm not opposed to it, if it , but that's out of scope for this PR. |
ok sure. |



No description provided.