Fixed #9036 (false positive: (style) Condition 's.x<127U' is always true)

This commit is contained in:
Daniel Marjamäki 2019-12-20 19:06:35 +01:00
parent bd83630f2e
commit 33ec78fe6e
2 changed files with 10 additions and 0 deletions

View File

@ -5779,6 +5779,8 @@ static void valueFlowContainerAfterCondition(TokenList *tokenlist,
static void valueFlowFwdAnalysis(const TokenList *tokenlist, const Settings *settings)
{
for (const Token *tok = tokenlist->front(); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "for ("))
tok = tok->linkAt(1);
if (tok->str() != "=" || !tok->astOperand1() || !tok->astOperand2())
continue;
if (!tok->scope()->isExecutable())

View File

@ -2762,6 +2762,14 @@ private:
"}";
values = tokenValues(code, "==");
ASSERT_EQUALS(true, values.empty());
// for loops
code = "struct S { int x; };\n" // #9036
"void foo(struct S s) {\n"
" for (s.x = 0; s.x < 127; s.x++) {}\n"
"}";
values = tokenValues(code, "<"); // TODO: comparison can be true or false
ASSERT_EQUALS(true, values.empty());
}
void valueFlowSwitchVariable() {