Fixed #7216 (ValueFlow: known value in condition)
This commit is contained in:
parent
c0056d2455
commit
5c9be4a0df
|
@ -1116,7 +1116,8 @@ static bool valueFlowForward(Token * const startToken,
|
|||
}
|
||||
|
||||
// if known variable is changed in loop body, change it to a possible value..
|
||||
handleKnownValuesInLoop(tok2, tok2->linkAt(1)->linkAt(1), &values, varid);
|
||||
if (Token::Match(tok2, "for|while"))
|
||||
handleKnownValuesInLoop(tok2, tok2->linkAt(1)->linkAt(1), &values, varid);
|
||||
|
||||
// Set values in condition
|
||||
for (Token* tok3 = tok2->tokAt(2); tok3 != tok2->next()->link(); tok3 = tok3->next()) {
|
||||
|
|
|
@ -1753,6 +1753,14 @@ private:
|
|||
ASSERT_EQUALS(3, value.intvalue);
|
||||
ASSERT(value.isKnown());
|
||||
|
||||
code = "void f() {\n"
|
||||
" int x = 15;\n"
|
||||
" if (x == 15) { x += 7; }\n" // <- condition is true
|
||||
"}";
|
||||
value = valueOfTok(code, "==");
|
||||
ASSERT_EQUALS(1, value.intvalue);
|
||||
ASSERT(value.isKnown());
|
||||
|
||||
code = "void f() {\n"
|
||||
" int x;\n"
|
||||
" if (ab) { x = 7; }\n"
|
||||
|
|
Loading…
Reference in New Issue