diff --git a/src/checkother.cpp b/src/checkother.cpp index c0f257ea5..3710dd41a 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -561,6 +561,26 @@ void CheckOther::checkConstantFunctionParameter() passedByValueError(tok, tok->strAt(10)); } + else if (Token::Match(tok, "[,(] const std :: %type% < std :: %type% , std :: %type% > %var% [,)]")) + { + passedByValueError(tok, tok->strAt(14)); + } + + else if (Token::Match(tok, "[,(] const std :: %type% < %type% , std :: %type% > %var% [,)]")) + { + passedByValueError(tok, tok->strAt(12)); + } + + else if (Token::Match(tok, "[,(] const std :: %type% < std :: %type% , %type% > %var% [,)]")) + { + passedByValueError(tok, tok->strAt(12)); + } + + else if (Token::Match(tok, "[,(] const std :: %type% < %type% , %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 2a6362995..2d6342bf3 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1019,54 +1019,38 @@ private: void passedByValue() { - { - testPassedByValue("void f(const std::string str)\n" - "{\n" - "}\n"); + testPassedByValue("void f(const std::string str) {}"); + ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'str' is passed by value. It could be passed by reference instead.\n", errout.str()); - ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'str' is passed by value. It could be passed by reference instead.\n", errout.str()); - } + testPassedByValue("class Foo;\nvoid f(const Foo foo) {}"); + ASSERT_EQUALS("[test.cpp:2]: (style) Function parameter 'foo' is passed by value. It could be passed by reference instead.\n", errout.str()); - { - testPassedByValue("class Foo;\n" - "void f(const Foo foo)\n" - "{\n" - "}\n"); + testPassedByValue("void f(const std::string &str) {}"); + ASSERT_EQUALS("", errout.str()); - ASSERT_EQUALS("[test.cpp:2]: (style) Function parameter 'foo' is passed by value. It could be passed by reference instead.\n", errout.str()); - } + testPassedByValue("void f(const std::vector v) {}"); + 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::string &str)\n" - "{\n" - "}\n"); + testPassedByValue("void f(const std::vector v) {}"); + ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead.\n", errout.str()); - ASSERT_EQUALS("", errout.str()); - } + testPassedByValue("void f(const std::vector &v) {}"); + ASSERT_EQUALS("", errout.str()); - { - testPassedByValue("void f(const std::vector v)\n" - "{\n" - "}\n"); + testPassedByValue("void f(const std::map &v) {}"); + ASSERT_EQUALS("", errout.str()); - 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::map v) {}"); + 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"); + testPassedByValue("void f(const std::map v) {}"); + ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead.\n", errout.str()); - 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::map v) {}"); + 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()); - } + testPassedByValue("void f(const std::map v) {}"); + ASSERT_EQUALS("[test.cpp:1]: (style) Function parameter 'v' is passed by value. It could be passed by reference instead.\n", errout.str()); } };