@@ -1466,7 +1466,7 @@ void CheckCondition::alwaysTrueFalse()
14661466 for (const Token* tok = scope->bodyStart ->next (); tok != scope->bodyEnd ; tok = tok->next ()) {
14671467 if (Token::simpleMatch (tok, " <" ) && tok->link ()) // don't write false positives when templates are used
14681468 continue ;
1469- if (!tok->hasKnownIntValue ())
1469+ if (!tok->hasKnownBoolValue ())
14701470 continue ;
14711471 if (Token::Match (tok->previous (), " %name% (" ) && tok->previous ()->function ()) {
14721472 const Function* f = tok->previous ()->function ();
@@ -1490,6 +1490,8 @@ void CheckCondition::alwaysTrueFalse()
14901490 else if (parent->str () == " ;" && parent->astParent () && parent->astParent ()->astParent () &&
14911491 Token::simpleMatch (parent->astParent ()->astParent ()->previous (), " for (" ))
14921492 condition = parent->astParent ()->astParent ()->previous ();
1493+ else if (isBooleanFuncArg (tok))
1494+ condition = tok;
14931495 else
14941496 continue ;
14951497 }
@@ -1580,14 +1582,17 @@ void CheckCondition::alwaysTrueFalse()
15801582 if (hasSizeof)
15811583 continue ;
15821584
1583- alwaysTrueFalseError (tok, condition, &tok->values ().front ());
1585+ auto it = std::find_if (tok->values ().begin (), tok->values ().end (), [](const ValueFlow::Value& v) {
1586+ return v.isIntValue ();
1587+ });
1588+ alwaysTrueFalseError (tok, condition, &*it);
15841589 }
15851590 }
15861591}
15871592
15881593void CheckCondition::alwaysTrueFalseError (const Token* tok, const Token* condition, const ValueFlow::Value* value)
15891594{
1590- const bool alwaysTrue = value && (value->intvalue != 0 );
1595+ const bool alwaysTrue = value && (value->intvalue != 0 || value-> isImpossible () );
15911596 const std::string expr = tok ? tok->expressionString () : std::string (" x" );
15921597 const std::string conditionStr = (Token::simpleMatch (condition, " return" ) ? " Return value" : " Condition" );
15931598 const std::string errmsg = conditionStr + " '" + expr + " ' is always " + (alwaysTrue ? " true" : " false" );
0 commit comments