Fixed false positive #5976: Properly handle shift from stream.

This commit is contained in:
PKEuS 2014-07-17 09:33:07 +02:00
parent 15bb447fdc
commit 8c96cc59c9
2 changed files with 14 additions and 1 deletions

View File

@ -997,7 +997,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
} else // addressof
variables.use(tok->next()->varId(), tok); // use = read + write
} else if (Token::Match(tok, ">>|>>= %var%")) {
if (_tokenizer->isC() || (tok->previous()->variable() && tok->previous()->variable()->typeEndToken()->isStandardType()))
if (_tokenizer->isC() || (tok->previous()->variable() && tok->previous()->variable()->typeEndToken()->isStandardType() && tok->astOperand1()->str() != ">>"))
variables.read(tok->next()->varId(), tok);
else
variables.use(tok->next()->varId(), tok); // use = read + write

View File

@ -1682,6 +1682,19 @@ private:
" if (c >> x) {}\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'x' is not assigned a value.\n", errout.str());
functionVariableUsage("void f() {\n"
" int x, y;\n"
" std::cin >> x >> y;\n"
"}");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("void f() {\n"
" int x, y;\n"
" std::cin >> (x >> y);\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'x' is not assigned a value.\n"
"[test.cpp:2]: (style) Variable 'y' is not assigned a value.\n", errout.str());
}
void localvar33() { // ticket #2345