Fixed #5922 (FP: passedByValue for std::string::value_type)

This commit is contained in:
Daniel Marjamäki 2014-07-18 15:51:59 +02:00
parent 6c44c20183
commit 2cc31acabb
2 changed files with 4 additions and 1 deletions

View File

@ -1978,7 +1978,7 @@ void CheckOther::checkConstantFunctionParameter()
// namespace and add them to the pattern. There are // namespace and add them to the pattern. There are
// streams for example (however it seems strange with // streams for example (however it seems strange with
// const stream parameter). // const stream parameter).
if (Token::Match(tok, "std :: string|wstring")) { if (Token::Match(tok, "std :: string|wstring !!::")) {
passedByValueError(tok, var->name()); passedByValueError(tok, var->name());
} else if (Token::Match(tok, "std :: %type% <") && !Token::simpleMatch(tok->linkAt(3), "> ::")) { } else if (Token::Match(tok, "std :: %type% <") && !Token::simpleMatch(tok->linkAt(3), "> ::")) {
passedByValueError(tok, var->name()); passedByValueError(tok, var->name());

View File

@ -1577,6 +1577,9 @@ private:
testPassedByValue("void f(const std::string str) {}"); testPassedByValue("void f(const std::string str) {}");
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by reference.\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by reference.\n", errout.str());
testPassedByValue("void f(const std::string::size_type x) {}");
ASSERT_EQUALS("", 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' should be passed by reference.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (performance) Function parameter 'foo' should be passed by reference.\n", errout.str());