From c209a77d710a665d34c4a9226d010dfdef1b0144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Tue, 7 Apr 2026 14:07:09 +0200 Subject: [PATCH 1/3] Add test --- test/testunusedvar.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 75fe4e85e1d..6046179c744 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -6681,6 +6681,10 @@ class TestUnusedVar : public TestFixture { " C c(12);\n" "}"); ASSERT_EQUALS("", errout_str()); + + functionVariableUsage("class S { S(int); };\n" + "void f() { S s = 0; }\n"); + ASSERT_EQUALS("", errout_str()); } void localVarSmartPtr() { From 7649f991dd6bb3aad9704811984c60044224005a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Tue, 7 Apr 2026 14:02:46 +0200 Subject: [PATCH 2/3] fix #14643 --- lib/checkunusedvar.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 6e9381657b0..e354878d6c4 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1352,6 +1352,14 @@ void CheckUnusedVar::checkFunctionVariableUsage() if (tok->previous() && tok->previous()->variable() && tok->previous()->variable()->nameToken()->scope()->type == ScopeType::eUnion) continue; + if (expr->valueType() && + expr->valueType()->type == ValueType::RECORD && + !expr->valueType()->pointer && + expr->valueType()->typeScope && + expr->valueType()->typeScope->definedType && + !symbolDatabase->isRecordTypeWithoutSideEffects(expr->valueType()->typeScope->definedType)) + continue; + FwdAnalysis fwdAnalysis(*mSettings); const Token* scopeEnd = ValueFlow::getEndOfExprScope(expr, scope, /*smallest*/ false); if (fwdAnalysis.unusedValue(expr, start, scopeEnd)) { From 887353da591ca6b8d7a6ea8e4d05983f9ed23a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 8 Apr 2026 11:33:06 +0200 Subject: [PATCH 3/3] Add tests for other tickets --- test/testunusedvar.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 6046179c744..f5f545d5079 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -6682,9 +6682,33 @@ class TestUnusedVar : public TestFixture { "}"); ASSERT_EQUALS("", errout_str()); + // #14643 functionVariableUsage("class S { S(int); };\n" "void f() { S s = 0; }\n"); ASSERT_EQUALS("", errout_str()); + + // #10965 + functionVariableUsage("class A {\n" + "public:\n" + " A();\n" + "};\n" + "extern A cb();\n" + "void f() { const A c = cb(); }\n"); + ASSERT_EQUALS("", errout_str()); + + // #11704 + functionVariableUsage("class S {\n" + "public:\n" + " S();\n" + "};\n" + "class C {\n" + " S &s();\n" + " void f() {\n" + " const S s1 = s(); // warning\n" + " const S s2; // no warning\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); } void localVarSmartPtr() {