diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 13ad6d29577..49900675bc9 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1591,6 +1591,21 @@ void CheckOther::checkPassByReference() if (var->isArray() && (!var->isStlType() || Token::simpleMatch(var->nameToken()->next(), "["))) continue; + if (var->isArgument()) { + const Token *tok = var->typeStartToken(); + for (; tok; tok = tok->next()) { + if (Token::simpleMatch(tok, "(")) { + tok = tok->link(); + continue; + } + if (Token::simpleMatch(tok, ")")) + break; + } + + if (Token::simpleMatch(tok, ") ;")) + continue; + } + const bool isConst = var->isConst(); if (isConst) { passedByValueError(var, inconclusive, isRangeBasedFor); diff --git a/test/testother.cpp b/test/testother.cpp index bac5dfbdf7f..a83b5058eac 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2910,6 +2910,9 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); check("struct X { int a[5]; }; void f(const X v);"); + ASSERT_EQUALS("", errout_str()); + + check("struct X { int a[5]; }; void f(const X v) { (void) v; }"); ASSERT_EQUALS("[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str()); check("extern \"C\" { struct X { int a[5]; }; void f(const X v); }"); @@ -4108,6 +4111,14 @@ class TestOther : public TestFixture { " if (*pp) {}\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("class C {\n" + "public:\n" + " explicit C(const std::string s);\n" + "private:\n" + " std::string _s;\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); } void constParameterCallback() {