From 5175e4ff3f04a7a8bb75c020694e262d456cf077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 9 Feb 2011 19:20:44 +0100 Subject: [PATCH] Fixed #2535 (false positive: (style) Variable 'A' is not assigned a value) --- lib/checkother.cpp | 5 +++-- test/testunusedvar.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 891502d6e..1e94d1b33 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1912,8 +1912,6 @@ void CheckOther::functionVariableUsage() variables.use(tok->next()->varId()); // use = read + write else if (Token::Match(tok, "[;{}] %var% >>")) variables.use(tok->next()->varId()); // use = read + write - else if (Token::Match(tok, "[{,] %var% [,}]")) - variables.read(tok->next()->varId()); // function parameter else if (Token::Match(tok, "[(,] %var% [")) @@ -1932,6 +1930,9 @@ void CheckOther::functionVariableUsage() variables.read(tok->tokAt(2)->varId()); } + else if (Token::Match(tok, "[{,] %var% [,}]")) + variables.read(tok->next()->varId()); + else if (Token::Match(tok, "%var% .")) variables.use(tok->varId()); // use = read + write diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index a417ccf5f..c782364f2 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -82,6 +82,7 @@ private: TEST_CASE(localvar32); // ticket #2330 TEST_CASE(localvar33); // ticket #2346 TEST_CASE(localvar34); // ticket #2368 + TEST_CASE(localvar35); // ticket #2535 TEST_CASE(localvaralias1); TEST_CASE(localvaralias2); // ticket #1637 TEST_CASE(localvaralias3); // ticket #1639 @@ -1372,6 +1373,15 @@ private: ASSERT_EQUALS("", errout.str()); } + void localvar35() // ticket #2535 + { + functionVariableUsage("void f() {\n" + " int a, b;\n" + " x(1,a,b);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void localvaralias1() { functionVariableUsage("void foo()\n"