diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 1bf120ee2..fc7919c71 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1912,7 +1912,6 @@ void CheckOther::functionVariableUsage() tok = tok->tokAt(3); variables.addVar(tok, Variables::standard, info, tok->next()->str() == "=" || isStatic); - tok = tok->next(); } // standard struct type declaration with possible initialization diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 75b927f19..34fbdd5be 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -99,7 +99,8 @@ private: TEST_CASE(localvardynamic1); TEST_CASE(localvardynamic2); // ticket #2904 TEST_CASE(localvararray1); // ticket #2780 - TEST_CASE(localvarstring); + TEST_CASE(localvarstring1); + TEST_CASE(localvarstring2); // ticket #2929 // Don't give false positives for variables in structs/unions TEST_CASE(localvarStruct1); @@ -2889,7 +2890,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarstring() // ticket #1597 + void localvarstring1() // ticket #1597 { functionVariableUsage("void foo() {\n" " std::string s;\n" @@ -2919,6 +2920,16 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); } + + void localvarstring2() // ticket #2929 + { + functionVariableUsage("void foo() {\n" + " std::string s;\n" + " int i;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (style) Unused variable: s\n" + "[test.cpp:3]: (style) Unused variable: i\n", errout.str()); + } }; REGISTER_TEST(TestUnusedVar)