From 8ff1e71b22d0bb0ce6464e423a1750a92271d73e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 31 Aug 2010 20:58:37 +0200 Subject: [PATCH 1/2] Fixed #2004 (False positive in 'variable assigned a value but is never used' check) --- lib/checkother.cpp | 8 +++++++- test/testunusedvar.cpp | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 80526356a..3be0a0025 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1634,7 +1634,6 @@ void CheckOther::functionVariableUsage() else { Variables::VariableUsage *var = variables.find(varid1); - if (var && var->_type == Variables::reference) { variables.writeAliases(varid1); @@ -1642,6 +1641,13 @@ void CheckOther::functionVariableUsage() } else variables.write(varid1); + + Variables::VariableUsage *var2 = variables.find(tok->varId()); + if (var2 && var2->_type == Variables::reference) + { + variables.writeAliases(tok->varId()); + variables.read(tok->varId()); + } } const Token *equal = tok->next(); diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index f56c2fa86..d0197ee91 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -81,6 +81,7 @@ private: TEST_CASE(localvaralias7); // ticket #1732 TEST_CASE(localvaralias8); TEST_CASE(localvaralias9); // ticket #1996 + TEST_CASE(localvaralias10); // ticket #2004 TEST_CASE(localvarasm); TEST_CASE(localvarstatic); @@ -2146,6 +2147,17 @@ private: ASSERT_EQUALS("", errout.str()); } + void localvaralias10() // ticket 2004 + { + functionVariableUsage("void foo(Foo &foo)\n" + "{\n" + " Foo &ref = foo;\n" + " int *x = &ref.x();\n" + " *x = 0;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void localvarasm() { functionVariableUsage("void foo(int &b)\n" From 688b2aefe9689d70abc2c00eb2ab34f24ff12bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 31 Aug 2010 21:04:17 +0200 Subject: [PATCH 2/2] Tokenizer: Fixed warnings about unsigned / signed conversion --- lib/tokenize.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2754b9b1d..0acfb56f8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3403,7 +3403,7 @@ void Tokenizer::simplifySizeof() { Token tempTok(0); tempTok.str("*"); - sizeOfVar[varId] = MathLib::toString(sizeOfType(&tempTok)); + sizeOfVar[varId] = MathLib::toString(sizeOfType(&tempTok)); } else if (Token::Match(tok->tokAt(-1), "%type% %var% [ ] = %str% ;")) @@ -3547,7 +3547,7 @@ void Tokenizer::simplifySizeof() if (Token::Match(tok->next(), "( * )")) { - tok->str(MathLib::toString(sizeOfType(tok->tokAt(2)))); + tok->str(MathLib::toString(sizeOfType(tok->tokAt(2)))); Token::eraseTokens(tok, tok->tokAt(4)); }