From e85eefb89a9d8200f78af154cf701f4d46716b57 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/3] 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 713c70c2dafc625e909261b64fa05a501b9806bc 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/3] 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 0a6633ed693b0caa02500b8b17977c08991bf68e 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/3] fix --- lib/checkother.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 13ad6d29577..7edc19f533e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1591,8 +1591,23 @@ void CheckOther::checkPassByReference() if (var->isArray() && (!var->isStlType() || Token::simpleMatch(var->nameToken()->next(), "["))) continue; + bool argWithNoBody = false; + if (var->isArgument()) { + const Token *tok = var->nameToken(); + for (; tok; tok = tok->next()) { + if (Token::simpleMatch(tok, "(")) { + tok = tok->link(); + continue; + } + if (Token::simpleMatch(tok, ")")) + break; + } + + argWithNoBody = Token::simpleMatch(tok, ") ;"); + } + const bool isConst = var->isConst(); - if (isConst) { + if (isConst && !argWithNoBody) { passedByValueError(var, inconclusive, isRangeBasedFor); continue; }