AssignIf: added todo test case (pass variable by value to function)

This commit is contained in:
Daniel Marjamäki 2013-07-29 12:27:57 +02:00
parent 39ba0d36c1
commit 1bebf1fd7e
2 changed files with 9 additions and 0 deletions

View File

@ -100,6 +100,7 @@ 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
return true; return true;
if (tok2->str() == "}") if (tok2->str() == "}")
return false; return false;

View File

@ -166,6 +166,14 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void do_something(int);\n"
"void f(int x) {\n"
" int y = x & 7;\n"
" do_something(y);\n" // passing variable by value => error
" if (y==8);\n"
"}");
TODO_ASSERT_EQUALS("error", "", 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"
" do_something();\n" " do_something();\n"