AssignIf: Improved handling of function calls
This commit is contained in:
parent
f420de24ef
commit
fd26bad6fa
|
@ -99,9 +99,22 @@ bool CheckAssignIf::assignIfParseScope(const Token * const assignTok,
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Token::Match(tok2, "[(,] &| %varid% [,)]", varid))
|
if (Token::Match(tok2, "[(,] &| %varid% [,)]", varid)) {
|
||||||
// TODO: don't bailout if variable is passed by value
|
unsigned int argumentNumber = 0;
|
||||||
|
const Token *ftok;
|
||||||
|
for (ftok = tok2; ftok && ftok->str() != "("; ftok = ftok->previous()) {
|
||||||
|
if (ftok->str() == ")")
|
||||||
|
ftok = ftok->link();
|
||||||
|
else if (ftok->str() == ",")
|
||||||
|
argumentNumber++;
|
||||||
|
}
|
||||||
|
ftok = ftok ? ftok->previous() : NULL;
|
||||||
|
if (!(ftok && ftok->function()))
|
||||||
return true;
|
return true;
|
||||||
|
const Variable *par = ftok->function()->getArgumentVar(argumentNumber);
|
||||||
|
if (par == NULL || par->isReference() || par->isPointer())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (tok2->str() == "}")
|
if (tok2->str() == "}")
|
||||||
return false;
|
return false;
|
||||||
if (Token::Match(tok2, "break|continue|return"))
|
if (Token::Match(tok2, "break|continue|return"))
|
||||||
|
|
|
@ -169,10 +169,10 @@ private:
|
||||||
check("void do_something(int);\n"
|
check("void do_something(int);\n"
|
||||||
"void f(int x) {\n"
|
"void f(int x) {\n"
|
||||||
" int y = x & 7;\n"
|
" int y = x & 7;\n"
|
||||||
" do_something(y);\n" // passing variable by value => error
|
" do_something(y);\n"
|
||||||
" if (y==8);\n"
|
" if (y==8);\n"
|
||||||
"}");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Mismatching assignment and comparison, comparison 'y==8' is always false.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" extern int y; y = x & 7;\n"
|
" extern int y; y = x & 7;\n"
|
||||||
|
|
Loading…
Reference in New Issue