From ab1d0a6798247edc4fd45b19fb1d75a0704a892c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 1 Apr 2026 10:57:06 +0200 Subject: [PATCH 1/4] Update checkunusedvar.cpp --- lib/checkunusedvar.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 6e9381657b0..992821b7152 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -424,6 +424,9 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de Variables::VariableUsage *var1 = variables.find(varid1); if (var1) { + if (var1->mType == Variables::pointerArray) + variables.use(varid1, tok); + // jump behind '=' tok = tok->next(); while (!tok->isAssignmentOp()) { @@ -567,8 +570,10 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de } else if (var1->mType == Variables::standard && addressOf) { variables.alias(varid1, varid2, true); } else { - if ((var2->mType == Variables::pointer || var2->mType == Variables::pointerArray) && tok->strAt(1) == "[") + if (var2->mType == Variables::pointer || var2->mType == Variables::pointerArray) { + variables.alias(varid1, varid2, true); variables.readAliases(varid2, tok); + } variables.read(varid2, tok); } @@ -1393,7 +1398,7 @@ void CheckUnusedVar::checkFunctionVariableUsage() // skip things that are only partially implemented to prevent false positives if (usage.mType == Variables::pointerPointer || - usage.mType == Variables::pointerArray || + //usage.mType == Variables::pointerArray || usage.mType == Variables::referenceArray) continue; From 082024921ce58f4c7b3ddf4317a5c4d73fd48a49 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 1 Apr 2026 10:58:18 +0200 Subject: [PATCH 2/4] Update testunusedvar.cpp --- test/testunusedvar.cpp | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 75fe4e85e1d..2be07bd8cb6 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -2876,25 +2876,25 @@ class TestUnusedVar : public TestFixture { "{\n" " int * i[2];\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\n", "", errout_str()); + ASSERT_EQUALS("[test.cpp:3:11]: (style) Unused variable: i [unusedVariable]\n", errout_str()); functionVariableUsage("void foo()\n" "{\n" " const int * i[2];\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\n", "", errout_str()); + ASSERT_EQUALS("[test.cpp:3:17]: (style) Unused variable: i [unusedVariable]\n", errout_str()); functionVariableUsage("void foo()\n" "{\n" " void * i[2];\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\n", "", errout_str()); + ASSERT_EQUALS("[test.cpp:3:12]: (style) Unused variable: i [unusedVariable]\n", errout_str()); functionVariableUsage("void foo()\n" "{\n" " const void * i[2];\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:3:9]: (style) Unused variable: i [unusedVariable]\n", "", errout_str()); + ASSERT_EQUALS("[test.cpp:3:18]: (style) Unused variable: i [unusedVariable]\n", errout_str()); functionVariableUsage("void foo()\n" "{\n" @@ -5813,22 +5813,6 @@ class TestUnusedVar : public TestFixture { " {}\n" "}"); ASSERT_EQUALS("", errout_str()); - - functionVariableUsage("void f(const int* b, int x) {\n" // #11125 - " int a[6];\n" - " int i = 0;\n" - " for (int j = 0; j < 6; ++j) {\n" - " if (b[j] != 0) {\n" - " a[i] = j;\n" - " ++i;\n" - " }\n" - " }\n" - " if (i > 1) {\n" - " a[i] = a[0];\n" - " (void)a[x];\n" - " }\n" - "}\n"); - ASSERT_EQUALS("", errout_str()); } void localvarForEach() { // #4155 - foreach From 51a19ddc0aff08a2e47a5a4a5cca2b059f58b22b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 1 Apr 2026 11:00:32 +0200 Subject: [PATCH 3/4] Update testunusedvar.cpp --- test/testunusedvar.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 2be07bd8cb6..44bc750daaa 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -5813,6 +5813,22 @@ class TestUnusedVar : public TestFixture { " {}\n" "}"); ASSERT_EQUALS("", errout_str()); + + functionVariableUsage("void f(const int* b, int x) {\n" // #11125 + " int a[6];\n" + " int i = 0;\n" + " for (int j = 0; j < 6; ++j) {\n" + " if (b[j] != 0) {\n" + " a[i] = j;\n" + " ++i;\n" + " }\n" + " }\n" + " if (i > 1) {\n" + " a[i] = a[0];\n" + " (void)a[x];\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void localvarForEach() { // #4155 - foreach From 6a84ab91e8c484cba3400f2aa0625b9b9923ffb7 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 1 Apr 2026 11:01:13 +0200 Subject: [PATCH 4/4] Update checkunusedvar.cpp --- lib/checkunusedvar.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 992821b7152..3aa9b7a6d74 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1398,7 +1398,6 @@ void CheckUnusedVar::checkFunctionVariableUsage() // skip things that are only partially implemented to prevent false positives if (usage.mType == Variables::pointerPointer || - //usage.mType == Variables::pointerArray || usage.mType == Variables::referenceArray) continue;