Fix FP uninitvar when stream bool operator is used

This commit is contained in:
Daniel Marjamäki 2018-04-18 16:13:24 +02:00
parent 3b68c913cb
commit 26e36a1d6b
2 changed files with 6 additions and 3 deletions

View File

@ -631,13 +631,16 @@ bool isLikelyStreamRead(bool cpp, const Token *op)
if (!cpp)
return false;
if (!Token::Match(op, "& %name% ;|&") && !Token::Match(op, ">> %name% ;|>>"))
if (!Token::Match(op, "&|>>") || !op->astOperand2())
return false;
if (!Token::Match(op->astOperand2(), "%name%|.|*|[") && op->str() != op->astOperand2()->str())
return false;
const Token *parent = op;
while (parent->astParent() && parent->astParent()->str() == op->str())
parent = parent->astParent();
if (parent->astParent())
if (parent->astParent() && !Token::Match(parent->astParent(), "%oror%|&&|(|,|!"))
return false;
if (!parent->astOperand1() || !parent->astOperand2())
return false;

View File

@ -2196,7 +2196,7 @@ private:
{
const char code[] = "void f() {\n"
" int x;\n"
" i >> x;\n"
" if (i >> x) { }\n"
"}";
checkUninitVar(code, "test.cpp");
ASSERT_EQUALS("", errout.str());