ValueFlow: Better handling of Known/Possible values after conditional unknown function call
This commit is contained in:
parent
7f6b6e43b1
commit
ffc707246b
|
@ -279,6 +279,17 @@ static bool isVariableChanged(const Token *start, const Token *end, const unsign
|
|||
if (Token::Match(tok->tokAt(-2), "[(,] & %var% [,)]"))
|
||||
return true; // TODO: check if function parameter is const
|
||||
|
||||
if (Token::Match(tok->previous(), "[(,] %var% [,)]")) {
|
||||
const Token *parent = tok->astParent();
|
||||
while (parent && parent->str() == ",")
|
||||
parent = parent->astParent();
|
||||
if (parent && parent->str() == "(") {
|
||||
if (parent->astOperand1()->isName() && !parent->astOperand1()->function())
|
||||
return true;
|
||||
// TODO: check if function parameter is non-const reference etc..
|
||||
}
|
||||
}
|
||||
|
||||
const Token *parent = tok->astParent();
|
||||
while (Token::Match(parent, ".|::"))
|
||||
parent = parent->astParent();
|
||||
|
|
|
@ -1579,6 +1579,13 @@ private:
|
|||
ASSERT_EQUALS(9, value.intvalue);
|
||||
ASSERT_EQUALS(ValueFlow::Value::ValueKind::Possible, value.valueKind);
|
||||
|
||||
code = "void f() {\n"
|
||||
" int x = 0;\n"
|
||||
" if (y) { dostuff(x); }\n"
|
||||
" if (!x) {}\n"
|
||||
"}\n";
|
||||
ASSERT(isNotKnownValues(code, "!"));
|
||||
|
||||
code = "void f() {\n"
|
||||
" int x = 0;\n"
|
||||
" for (int i = 0; i < 10; i++) {\n"
|
||||
|
|
Loading…
Reference in New Issue