Fixed #1894 (unreadVariable false positive with const references)

This commit is contained in:
Daniel Marjamäki 2010-08-07 15:53:51 +02:00
parent 050011d287
commit ed4f1164a1
2 changed files with 14 additions and 0 deletions

View File

@ -913,6 +913,9 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference
unsigned int varid2;
bool addressOf = false;
if (Token::Match(tok->tokAt(start), "%var% ."))
variables.use(tok->tokAt(start)->varId()); // use = read + write
// check for C style cast
if (tok->tokAt(start)->str() == "(")
{

View File

@ -71,6 +71,7 @@ private:
TEST_CASE(localvar23); // ticket #1808
TEST_CASE(localvar24); // ticket #1803
TEST_CASE(localvar25); // ticket #1729
TEST_CASE(localvar26); // ticket #1894
TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637
TEST_CASE(localvaralias3); // ticket #1639
@ -1246,6 +1247,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvar26() // ticket #1894
{
functionVariableUsage("int main() {\n"
" const Fred &fred = getfred();\n"
" int *p = fred.x();\n"
" *p = 0;"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvaralias1()
{
functionVariableUsage("void foo()\n"