From 837605b05b543414ae48a6d279b805cc0d83cf6f Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 27 Nov 2010 10:46:34 +0200 Subject: [PATCH] Ticket #2239 (Too long "short" message about function parameter passing) Have a proper short message for the parameter passing warning and improve the message. --- lib/checkother.cpp | 5 ++++- test/testother.cpp | 16 ++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 3a7731d1f..703a8408b 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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) diff --git a/test/testother.cpp b/test/testother.cpp index b90b641eb..0939ee69c 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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 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 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 &v) {}"); ASSERT_EQUALS("", errout.str()); @@ -707,16 +707,16 @@ private: ASSERT_EQUALS("", errout.str()); testPassedByValue("void f(const std::map 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 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 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 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()