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;
|
continue;
|
||||||
addVD(tok->tokAt(2));
|
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,
|
reportError(tok,
|
||||||
"error",
|
"error",
|
||||||
"autoVariables",
|
"autoVariables",
|
||||||
"Wrong assignement of an auto-variable to an effective parameter of a function");
|
"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,
|
reportError(tok,
|
||||||
"error",
|
"error",
|
||||||
"autoVariables",
|
"autoVariables",
|
||||||
|
|
|
@ -75,6 +75,13 @@ private:
|
||||||
" int num=2;"
|
" int num=2;"
|
||||||
"res=#}");
|
"res=#}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Wrong assignement of an auto-variable to an effective parameter of a function\n", errout.str());
|
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()
|
void testautovararray()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue