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/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)); } 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"