diff --git a/src/checkother.cpp b/src/checkother.cpp index 98c84d204..16632b8f0 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -914,7 +914,7 @@ void CheckOther::functionVariableUsage() varUsage[ tok->strAt(1)] |= USAGE_WRITE; if (Token::Match(tok, ">>|& %var%")) - varUsage[ tok->strAt(1)] |= USAGE_WRITE; + varUsage[ tok->strAt(1)] |= (USAGE_WRITE | USAGE_READ); if ((Token::Match(tok, "[(=&!]") || isOp(tok)) && Token::Match(tok->next(), "%var%")) varUsage[ tok->strAt(1)] |= USAGE_READ; diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 1b531ba91..789a497f9 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -76,6 +76,7 @@ private: TEST_CASE(localvarIfElse); // return tmp1 ? tmp2 : tmp3; TEST_CASE(localvarOpAssign); // a |= b; TEST_CASE(localvarFor); // for ( ; var; ) + TEST_CASE(localvarShift); // 1 >> var } void structmember1() @@ -346,6 +347,15 @@ private: ASSERT_EQUALS(std::string(""), errout.str()); } + void localvarShift() + { + functionVariableUsage("int foo()\n" + "{\n" + " int var = 1;\n" + " return 1 >> var;\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } }; REGISTER_TEST(TestUnusedVar)