Ticket #2239 (Too long "short" message about function parameter passing)

Have a proper short message for the parameter passing warning and
improve the message.
This commit is contained in:
Kimmo Varis 2010-11-27 10:46:34 +02:00
parent 9b4b8b2abe
commit 837605b05b
2 changed files with 12 additions and 9 deletions

View File

@ -2519,7 +2519,10 @@ void CheckOther::unusedStructMemberError(const Token *tok, const std::string &st
void CheckOther::passedByValueError(const Token *tok, const std::string &parname)
{
reportError(tok, Severity::performance, "passedByValue", "Function parameter '" + parname + "' is passed by value. It could be passed by reference instead, to make it faster.");
reportError(tok, Severity::performance, "passedByValue",
"Function parameter '" + parname + "' should be passed by reference.\n "
"parameter '" + parname + "' is passed as a value. It could be passed "
"as a (const) reference which is usually faster and recommended in C++.");
}
void CheckOther::constStatementError(const Token *tok, const std::string &type)

View File

@ -686,19 +686,19 @@ private:
void passedByValue()
{
testPassedByValue("void f(const std::string str) {}");
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by reference.\n", errout.str());
testPassedByValue("class Foo;\nvoid f(const Foo foo) {}");
ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'foo' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'foo' should be passed by reference.\n", errout.str());
testPassedByValue("void f(const std::string &str) {}");
ASSERT_EQUALS("", errout.str());
testPassedByValue("void f(const std::vector<int> v) {}");
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by reference.\n", errout.str());
testPassedByValue("void f(const std::vector<std::string> v) {}");
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by reference.\n", errout.str());
testPassedByValue("void f(const std::vector<int> &v) {}");
ASSERT_EQUALS("", errout.str());
@ -707,16 +707,16 @@ private:
ASSERT_EQUALS("", errout.str());
testPassedByValue("void f(const std::map<int,int> v) {}");
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by reference.\n", errout.str());
testPassedByValue("void f(const std::map<std::string,std::string> v) {}");
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by reference.\n", errout.str());
testPassedByValue("void f(const std::map<int,std::string> v) {}");
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by reference.\n", errout.str());
testPassedByValue("void f(const std::map<std::string,int> v) {}");
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' is passed by value. It could be passed by reference instead, to make it faster.\n", errout.str());
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by reference.\n", errout.str());
}
void mathfunctionCall1()