From e5118ea364b4ce4109de00529fc5650ec2788437 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 9 Dec 2025 12:32:15 +0100 Subject: [PATCH 1/5] Update astutils.cpp --- lib/astutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 68218b4402d..933612a0645 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3678,7 +3678,7 @@ bool isGlobalData(const Token *expr) // TODO check if pointer points at local data const Variable *lhsvar = tok->astOperand1()->variable(); const ValueType *lhstype = tok->astOperand1()->valueType(); - if (lhsvar->isPointer()) { + if (lhsvar->isPointer() || !lhstype || lhstype == ValueType::Type::ITERATOR) { globalData = true; return ChildrenToVisit::none; } From ac86c6a994cb15c8a4611433c04dc5b9fb6a5fea Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 9 Dec 2025 12:36:55 +0100 Subject: [PATCH 2/5] Update testunusedvar.cpp --- test/testunusedvar.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 200f8252017..5b94a1f7fba 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -5228,6 +5228,13 @@ class TestUnusedVar : public TestFixture { " }\n" "}"); ASSERT_EQUALS("", errout_str()); + + functionVariableUsage("void f(const std::vector& v) {\n" // #13303 + " std::vector::const_iterator it = v.cbegin();\n" + " if (*it == 0)\n" + " it = v.cend();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4:12]: (style) Variable 'it' is assigned a value that is never used. [unreadVariable]\n", errout_str()); } void localvaralias19() { // #9828 From cf1ba81bb7e3b4f7fbafe42b9217997dc4c9062f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 9 Dec 2025 12:37:38 +0100 Subject: [PATCH 3/5] Update astutils.cpp --- lib/astutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 933612a0645..294aa622c0c 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3678,7 +3678,7 @@ bool isGlobalData(const Token *expr) // TODO check if pointer points at local data const Variable *lhsvar = tok->astOperand1()->variable(); const ValueType *lhstype = tok->astOperand1()->valueType(); - if (lhsvar->isPointer() || !lhstype || lhstype == ValueType::Type::ITERATOR) { + if (lhsvar->isPointer() || !lhstype || lhstype->type == ValueType::Type::ITERATOR) { globalData = true; return ChildrenToVisit::none; } From b1c68453d132e63fb2e4467fd4a8b633975098c7 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 9 Dec 2025 12:38:41 +0100 Subject: [PATCH 4/5] Update checkunusedvar.cpp --- lib/checkunusedvar.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index b807199ca30..ddaffa0f817 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1283,12 +1283,6 @@ void CheckUnusedVar::checkFunctionVariableUsage() if (!tok->astOperand1()) continue; - const Token *iteratorToken = tok->astOperand1(); - while (Token::Match(iteratorToken, "[.*]")) - iteratorToken = iteratorToken->astOperand1(); - if (iteratorToken && iteratorToken->variable() && iteratorToken->variable()->typeEndToken()->str().find("iterator") != std::string::npos) - continue; - const Token *op1tok = tok->astOperand1(); while (Token::Match(op1tok, ".|[|*")) op1tok = op1tok->astOperand1(); From 23590bed8b8c9790078ac6e5d10e2f8b71b21391 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:00:32 +0100 Subject: [PATCH 5/5] Update astutils.cpp --- lib/astutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 294aa622c0c..d5d38bc3453 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3686,7 +3686,7 @@ bool isGlobalData(const Token *expr) globalData = true; return ChildrenToVisit::none; } - if (lhsvar->isArgument() && (!lhstype || (lhstype->type <= ValueType::Type::VOID && !lhstype->container))) { + if (lhsvar->isArgument() && lhstype->type <= ValueType::Type::VOID && !lhstype->container) { globalData = true; return ChildrenToVisit::none; }