From ecad249ae2212d0d1631533ad036363427163db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 25 Dec 2010 19:17:53 +0100 Subject: [PATCH] Fixed #2346 (False positive: pointer is assigned value that is never used. used here: 'pCol = pCol->GetNext()') --- lib/checkother.cpp | 4 ++++ test/testunusedvar.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 0030cd9be..4127327f0 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1667,6 +1667,10 @@ void CheckOther::functionVariableUsage() else variables.write(varid1); } + else if (Token::Match(tok, "%varid% .", varid1)) + { + variables.use(varid1); + } else { variables.write(varid1); diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 72e5de6c7..00e302bbb 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -80,6 +80,7 @@ private: TEST_CASE(localvar30); TEST_CASE(localvar31); // ticket #2286 TEST_CASE(localvar32); // ticket #2330 + TEST_CASE(localvar33); // ticket #2346 TEST_CASE(localvaralias1); TEST_CASE(localvaralias2); // ticket #1637 TEST_CASE(localvaralias3); // ticket #1639 @@ -1346,6 +1347,17 @@ private: ASSERT_EQUALS("", errout.str()); } + void localvar33() // ticket #2345 + { + functionVariableUsage("void f() {\n" + " Abc* abc = getabc();\n" + " while (0 != (abc = abc->next())) {\n" + " ++nOldNum;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void localvaralias1() { functionVariableUsage("void foo()\n"