From 29760ce68c50c19704a64f60d1de341c2e22ffee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 16 Apr 2026 15:08:16 +0200 Subject: [PATCH 1/4] update test --- test/testother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index bac5dfbdf7f..6b808fd40b0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2909,7 +2909,7 @@ class TestOther : public TestFixture { check("struct X { int a[5]; }; extern \"C\" void f(X v) { }"); ASSERT_EQUALS("", errout_str()); - check("struct X { int a[5]; }; void f(const X v);"); + 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); }"); From 0357bb62bc5ff512622ff412a06e53655438468e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 16 Apr 2026 15:17:14 +0200 Subject: [PATCH 2/4] add test --- test/testother.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 6b808fd40b0..e55d34c44a5 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4108,6 +4108,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() { From 1380219c96d9aaa0ba8d3fa71004fde6c471c67f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 16 Apr 2026 15:08:11 +0200 Subject: [PATCH 3/4] fix --- lib/checkother.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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); From 86b80d3353a375f992f7190b96a1d55ac3586a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Tue, 21 Apr 2026 13:53:09 +0200 Subject: [PATCH 4/4] Update test/testother.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Oliver Stöneberg --- test/testother.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index e55d34c44a5..a83b5058eac 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2909,6 +2909,9 @@ class TestOther : public TestFixture { check("struct X { int a[5]; }; extern \"C\" void f(X v) { }"); 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());