From 1863306198b5b19745479453e9da671559f21499 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Tue, 11 Sep 2012 14:24:12 +0200 Subject: [PATCH] Fixed false negative in checkunusedvar.cpp and reduced code dupliaction. --- lib/checkunusedvar.cpp | 38 ++++---------------------------------- test/testunusedvar.cpp | 2 +- 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 42c64c125..095298b65 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -240,23 +240,8 @@ void Variables::readAliases(unsigned int varid, const Token* tok) void Variables::readAll(unsigned int varid, const Token* tok) { - VariableUsage *usage = find(varid); - - if (usage) { - usage->_read = true; - usage->_lastAccess = tok; - - std::set::iterator aliases; - - for (aliases = usage->_aliases.begin(); aliases != usage->_aliases.end(); ++aliases) { - VariableUsage *aliased = find(*aliases); - - if (aliased) { - aliased->_read = true; - aliased->_lastAccess = tok; - } - } - } + read(varid, tok); + readAliases(varid, tok); } void Variables::write(unsigned int varid, const Token* tok) @@ -291,23 +276,8 @@ void Variables::writeAliases(unsigned int varid, const Token* tok) void Variables::writeAll(unsigned int varid, const Token* tok) { - VariableUsage *usage = find(varid); - - if (usage) { - usage->_write = true; - usage->_lastAccess = tok; - - std::set::iterator aliases; - - for (aliases = usage->_aliases.begin(); aliases != usage->_aliases.end(); ++aliases) { - VariableUsage *aliased = find(*aliases); - - if (aliased) { - aliased->_write = true; - aliased->_lastAccess = tok; - } - } - } + write(varid, tok); + writeAliases(varid, tok); } void Variables::use(unsigned int varid, const Token* tok) diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 27599cebd..fbccd5e97 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1372,7 +1372,7 @@ private: " a = b[c] = 0;\n" " return a;\n" "}"); - ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'b' is assigned a value that is never used\n", errout.str()); } void localvar24() { // ticket #1803