File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1591,6 +1591,21 @@ void CheckOther::checkPassByReference()
15911591 if (var->isArray () && (!var->isStlType () || Token::simpleMatch (var->nameToken ()->next (), " [" )))
15921592 continue ;
15931593
1594+ if (var->isArgument ()) {
1595+ const Token *tok = var->typeStartToken ();
1596+ for (; tok; tok = tok->next ()) {
1597+ if (Token::simpleMatch (tok, " (" )) {
1598+ tok = tok->link ();
1599+ continue ;
1600+ }
1601+ if (Token::simpleMatch (tok, " )" ))
1602+ break ;
1603+ }
1604+
1605+ if (Token::simpleMatch (tok, " ) ;" ))
1606+ continue ;
1607+ }
1608+
15941609 const bool isConst = var->isConst ();
15951610 if (isConst) {
15961611 passedByValueError (var, inconclusive, isRangeBasedFor);
Original file line number Diff line number Diff line change @@ -2911,6 +2911,9 @@ class TestOther : public TestFixture {
29112911 ASSERT_EQUALS("", errout_str());
29122912
29132913 check("struct X { int a[5]; }; void f(const X v);");
2914+ ASSERT_EQUALS("", errout_str());
2915+
2916+ check("struct X { int a[5]; }; void f(const X v) { (void) v; }");
29142917 ASSERT_EQUALS("[test.cpp:1:40]: (performance) Function parameter 'v' should be passed by const reference. [passedByValue]\n", errout_str());
29152918
29162919 check("extern \"C\" { struct X { int a[5]; }; void f(const X v); }");
@@ -4109,6 +4112,14 @@ class TestOther : public TestFixture {
41094112 " if (*pp) {}\n"
41104113 "}\n");
41114114 ASSERT_EQUALS("", errout_str());
4115+
4116+ check("class C {\n"
4117+ "public:\n"
4118+ " explicit C(const std::string s);\n"
4119+ "private:\n"
4120+ " std::string _s;\n"
4121+ "};\n");
4122+ ASSERT_EQUALS("", errout_str());
41124123 }
41134124
41144125 void constParameterCallback() {
You can’t perform that action at this time.
0 commit comments