Fix #370 (Assign auto variable to parameter false positive)

This commit is contained in:
Daniel Marjamäki 2009-06-06 21:25:41 +02:00
parent a8c5526c84
commit 5747133fa8
2 changed files with 11 additions and 4 deletions

View File

@ -191,17 +191,17 @@ void CheckAutoVariables::autoVariables()
continue;
addVD(tok->tokAt(2));
}
else if (bindent > 0 && Token::Match(tok, "%var% = & %var%")) //Critical assignement
else if (bindent > 0 && Token::Match(tok, "[;{}] %var% = & %var%")) //Critical assignement
{
if (errorAv(tok->tokAt(0), tok->tokAt(3)))
if (errorAv(tok->tokAt(1), tok->tokAt(4)))
reportError(tok,
"error",
"autoVariables",
"Wrong assignement of an auto-variable to an effective parameter of a function");
}
else if (bindent > 0 && Token::Match(tok, "%var% [ %any% ] = & %var%")) //Critical assignement
else if (bindent > 0 && Token::Match(tok, "[;{}] %var% [ %any% ] = & %var%")) //Critical assignement
{
if (errorAv(tok->tokAt(0), tok->tokAt(6)))
if (errorAv(tok->tokAt(1), tok->tokAt(7)))
reportError(tok,
"error",
"autoVariables",

View File

@ -75,6 +75,13 @@ private:
" int num=2;"
"res=#}");
ASSERT_EQUALS("[test.cpp:3]: (error) Wrong assignement of an auto-variable to an effective parameter of a function\n", errout.str());
check("void func1(int **res)\n"
"{\n"
" int num = 2;\n"
" foo.res = #\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void testautovararray()
{