diff --git a/lib/checkother.cpp b/lib/checkother.cpp index bd1294a6e..ad72e0c08 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -535,6 +535,10 @@ void CheckOther::functionVariableUsage() else if (Token::Match(tok, "; %var% ;")) varUsage[ tok->strAt(1)].read = true; + + else if (Token::Match(tok, "++|-- %var%") || + Token::Match(tok, "%var% ++|--")) + varUsage[tok->strAt(1)].use(); } // Check usage of all variables in the current scope.. diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index eb616e88f..cd72bf21a 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -64,6 +64,7 @@ private: TEST_CASE(localvar3); TEST_CASE(localvar4); TEST_CASE(localvar5); + TEST_CASE(localvar6); // Don't give false positives for variables in structs/unions TEST_CASE(localvarStruct1); @@ -273,6 +274,18 @@ private: ASSERT_EQUALS(std::string(""), errout.str()); } + void localvar6() + { + functionVariableUsage("void foo()\n" + "{\n" + " int a = 0;\n" + " int b[10];\n" + " for (int i=0;i<10;++i)\n" + " b[i] = ++a;\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } + void localvarStruct1()