Fix #793 (Improve passedByValue check)

http://sourceforge.net/apps/trac/cppcheck/ticket/793
This commit is contained in:
Reijo Tomperi 2009-10-05 11:59:28 +03:00
parent 24c60c881a
commit 1df8f38423
2 changed files with 34 additions and 0 deletions

View File

@ -567,6 +567,16 @@ void CheckOther::checkConstantFunctionParameter()
passedByValueError(tok, tok->strAt(5)); passedByValueError(tok, tok->strAt(5));
} }
else if (Token::Match(tok, "[,(] const std :: %type% < %type% > %var% [,)]"))
{
passedByValueError(tok, tok->strAt(8));
}
else if (Token::Match(tok, "[,(] const std :: %type% < std :: %type% > %var% [,)]"))
{
passedByValueError(tok, tok->strAt(10));
}
else if (Token::Match(tok, "[,(] const %type% %var% [,)]")) else if (Token::Match(tok, "[,(] const %type% %var% [,)]"))
{ {
// Check if type is a struct or class. // Check if type is a struct or class.

View File

@ -1015,6 +1015,30 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
{
testPassedByValue("void f(const std::vector<int> v)\n"
"{\n"
"}\n");
ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead.\n", errout.str());
}
{
testPassedByValue("void f(const std::vector<std::string> v)\n"
"{\n"
"}\n");
ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead.\n", errout.str());
}
{
testPassedByValue("void f(const std::vector<int> &v)\n"
"{\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
} }
}; };