diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 68218b4402d..d5d38bc3453 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->type == ValueType::Type::ITERATOR) { globalData = true; return ChildrenToVisit::none; } @@ -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; } 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(); 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