* Fix #11434 FP knownConditionTrueFalse with loop over bool array * Simplify
This commit is contained in:
parent
0c1e2ceeb9
commit
553b579f8d
|
@ -1370,10 +1370,23 @@ static bool isForLoopCondition(const Token * const tok)
|
|||
parent->astParent()->astParent()->astOperand1()->str() == "for";
|
||||
}
|
||||
|
||||
static bool isForLoopIncrement(const Token* const tok)
|
||||
{
|
||||
if (!tok)
|
||||
return false;
|
||||
const Token *const parent = tok->astParent();
|
||||
return Token::simpleMatch(parent, ";") && parent->astOperand2() == tok &&
|
||||
Token::simpleMatch(parent->astParent(), ";") &&
|
||||
Token::simpleMatch(parent->astParent()->astParent(), "(") &&
|
||||
parent->astParent()->astParent()->astOperand1()->str() == "for";
|
||||
}
|
||||
|
||||
bool isUsedAsBool(const Token* const tok)
|
||||
{
|
||||
if (!tok)
|
||||
return false;
|
||||
if (isForLoopIncrement(tok))
|
||||
return false;
|
||||
if (astIsBool(tok))
|
||||
return true;
|
||||
if (Token::Match(tok, "!|&&|%oror%|%comp%"))
|
||||
|
|
|
@ -4973,6 +4973,13 @@ private:
|
|||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() {\n" // #11434
|
||||
" const int N = 5;\n"
|
||||
" bool a[N];\n"
|
||||
" for (int i = 0; i < N; a[i++] = false);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void alwaysTrueTryCatch()
|
||||
|
|
Loading…
Reference in New Issue