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:
parent
9b4b8b2abe
commit
837605b05b
|
@ -2519,7 +2519,10 @@ void CheckOther::unusedStructMemberError(const Token *tok, const std::string &st
|
||||||
|
|
||||||
void CheckOther::passedByValueError(const Token *tok, const std::string &parname)
|
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)
|
void CheckOther::constStatementError(const Token *tok, const std::string &type)
|
||||||
|
|
|
@ -686,19 +686,19 @@ private:
|
||||||
void passedByValue()
|
void passedByValue()
|
||||||
{
|
{
|
||||||
testPassedByValue("void f(const std::string str) {}");
|
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) {}");
|
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) {}");
|
testPassedByValue("void f(const std::string &str) {}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
testPassedByValue("void f(const std::vector<int> v) {}");
|
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) {}");
|
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) {}");
|
testPassedByValue("void f(const std::vector<int> &v) {}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -707,16 +707,16 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
testPassedByValue("void f(const std::map<int,int> v) {}");
|
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) {}");
|
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) {}");
|
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) {}");
|
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()
|
void mathfunctionCall1()
|
||||||
|
|
Loading…
Reference in New Issue