Fix #370 (Assign auto variable to parameter false positive)
This commit is contained in:
parent
a8c5526c84
commit
5747133fa8
|
@ -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",
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue