From a2febc49d6c3bfd7546038091538810742671309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 15 Nov 2012 08:36:43 +0100 Subject: [PATCH] Fixed #4318 (False positive: 'unreadVariable') --- lib/checkunusedvar.cpp | 11 ++++++----- test/testunusedvar.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 68ad423fb..3e307cbca 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -735,9 +735,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const variables.use(tok->tokAt(2)->varId(), tok); } // assignment - else if (!Token::Match(tok->tokAt(-2), "[;{}.] %var% (") && - (Token::Match(tok, "*| ++|--| %var% ++|--| =") || - Token::Match(tok, "*| ( const| %type% *| ) %var% ="))) { + else if (Token::Match(tok, "*| ++|--| %var% ++|--| =") || + Token::Match(tok, "*| ( const| %type% *| ) %var% =")) { bool dereference = false; bool pre = false; bool post = false; @@ -762,7 +761,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const post = true; const unsigned int varid1 = tok->varId(); - const Token *start = tok; + const Token * const start = tok; tok = doAssignment(variables, tok, dereference, scope); @@ -777,7 +776,9 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const variables.read(varid1, tok); } else { Variables::VariableUsage *var = variables.find(varid1); - if (var && var->_type == Variables::reference) { + if (var && Token::simpleMatch(start->previous(), ",")) { + variables.use(varid1, tok); + } else if (var && var->_type == Variables::reference) { variables.writeAliases(varid1, tok); variables.read(varid1, tok); } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 6ce2a7fcc..4910b0799 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1494,6 +1494,12 @@ private: " return a + b;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + functionVariableUsage("int f() {\n" // ticket #4318 + " int a,b;\n" + " x(a, b=2);\n" // <- if param2 is passed-by-reference then b might be used in x + "}\n"); + ASSERT_EQUALS("", errout.str()); } void localvar37() { // ticket #3078