diff --git a/src/checkother.cpp b/src/checkother.cpp index ab4b35ecd..fde9847a1 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -567,6 +567,16 @@ void CheckOther::checkConstantFunctionParameter() 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% [,)]")) { // Check if type is a struct or class. diff --git a/test/testother.cpp b/test/testother.cpp index b170aeb86..457ea3728 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1015,6 +1015,30 @@ private: ASSERT_EQUALS("", errout.str()); } + + { + testPassedByValue("void f(const std::vector 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 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 &v)\n" + "{\n" + "}\n"); + + ASSERT_EQUALS("", errout.str()); + } } };