diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index eb3b56144..a8601cd59 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -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 diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index b2da49dce..3f7238d7a 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -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