Repository navigation
Fix FP knowConditionTrueFalse - #4419
Conversation
| (Token::Match(tok->astParent(), "%oror%|&&") || Token::Match(tok->astParent()->astOperand1(), "if|while")); | ||
| const bool constValExpr = tok->isNumber() && Token::Match(tok->astParent(),"%oror%|&&|?"); // just one number in boolean expression | ||
| const bool compExpr = Token::Match(tok, "%comp%|!|("); // a compare expression | ||
| const bool compExpr = Token::Match(tok, "%comp%|!|(") && !((tok->previous() && tok->previous()->function()) || tok->isCast() || isCPPCast(tok)); // a compare expression |
There was a problem hiding this comment.
This variable is for a compare expression, it shouldn't have ( in the match. It would be better to have another variable like callExpr to check for function call expressions: callExpr = Token::simpleMatch(tok, "(") && astIsBool(tok) && !tok->isCast(). We probably only want to warn on functions that return bools.
It seems strange to skip user-defined function calls.
There was a problem hiding this comment.
It seems strange to skip user-defined function calls.
The fact that a function returns a known value might be seen as an implementation detail. I'd call this a FP:
http://cppcheck1.osuosl.org:8000/bali-phy
BAli-Phy-3.6.1/src/sequence/alphabet.cc:326:10: style: Condition 'T()' is always true [knownConditionTrueFalse]
There was a problem hiding this comment.
I thought isConstVarExpression would catch functions like that(from #4341)?
There was a problem hiding this comment.
This variable is for a compare expression, it shouldn't have
(in the match.
! is not really a compare expression either, see the inconsistencies reported in #10426. We also might want to distinguish between return expressions (warn for return type bool only) and actual conditions (warning for e.g. int is ok).
There was a problem hiding this comment.
Yea this whole thing needs a refactoring.
There was a problem hiding this comment.
Regarding known function return values, I just saw this in daca: static unsigned LZ4_64bits(void) { return sizeof(void*)==8; }
Warnings for this are probably not desirable. Also, there are functions that have #ifdefs inside.
No description provided.