Fixed #8195 (False positive uninitvar (regression) - valueflow misses variable initialization via istringstream >>)
This commit is contained in:
parent
33664a88d1
commit
30f04a5a96
|
@ -458,6 +458,15 @@ bool isVariableChanged(const Token *start, const Token *end, const unsigned int
|
|||
if (Token::Match(tok->previous(), "++|-- %name%"))
|
||||
return true;
|
||||
|
||||
if (Token::simpleMatch(tok->previous(), ">>")) {
|
||||
const Token *shr = tok->previous();
|
||||
if (Token::simpleMatch(shr->astParent(), ">>"))
|
||||
return true;
|
||||
const Token *lhs = shr->astOperand1();
|
||||
if (!lhs->valueType() || !lhs->valueType()->isIntegral())
|
||||
return true;
|
||||
}
|
||||
|
||||
const Token *ftok = tok;
|
||||
while (ftok && !Token::Match(ftok, "[({[]"))
|
||||
ftok = ftok->astParent();
|
||||
|
|
|
@ -2625,6 +2625,16 @@ private:
|
|||
" f(x=3), return x+3;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(0U, tokenValues(code, "x +").size());
|
||||
|
||||
// #8195
|
||||
code = "void foo(std::istream &is) {\n"
|
||||
" int x;\n"
|
||||
" if (is >> x) {\n"
|
||||
" a = x;\n"
|
||||
" }\n"
|
||||
"}";
|
||||
values = tokenValues(code, "x ; }");
|
||||
ASSERT_EQUALS(true, values.empty());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue