From c3c3eb74e8f0f9b4c31624301d46388a3f8836b1 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 21 Jul 2011 18:37:37 -0400 Subject: [PATCH] fix #2929 (Additional Unused variable check) --- lib/checkother.cpp | 1 - test/testunusedvar.cpp | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) 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)