Skip to content

Commit 33ec78f

Browse files
committed
Fixed #9036 (false positive: (style) Condition 's.x<127U' is always true)
1 parent bd83630 commit 33ec78f

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

lib/valueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5779,6 +5779,8 @@ static void valueFlowContainerAfterCondition(TokenList *tokenlist,
57795779
static void valueFlowFwdAnalysis(const TokenList *tokenlist, const Settings *settings)
57805780
{
57815781
for (const Token *tok = tokenlist->front(); tok; tok = tok->next()) {
5782+
if (Token::simpleMatch(tok, "for ("))
5783+
tok = tok->linkAt(1);
57825784
if (tok->str() != "=" || !tok->astOperand1() || !tok->astOperand2())
57835785
continue;
57845786
if (!tok->scope()->isExecutable())

test/testvalueflow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,6 +2762,14 @@ class TestValueFlow : public TestFixture {
27622762
"}";
27632763
values = tokenValues(code, "==");
27642764
ASSERT_EQUALS(true, values.empty());
2765+
2766+
// for loops
2767+
code = "struct S { int x; };\n" // #9036
2768+
"void foo(struct S s) {\n"
2769+
" for (s.x = 0; s.x < 127; s.x++) {}\n"
2770+
"}";
2771+
values = tokenValues(code, "<"); // TODO: comparison can be true or false
2772+
ASSERT_EQUALS(true, values.empty());
27652773
}
27662774

27672775
void valueFlowSwitchVariable() {

0 commit comments

Comments
 (0)