Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3678,15 +3678,15 @@ 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;
}
if (lhsvar->isArgument() && lhsvar->isArray()) {
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;
}
Expand Down
6 changes: 0 additions & 6 deletions lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5228,6 +5228,13 @@ class TestUnusedVar : public TestFixture {
" }\n"
"}");
ASSERT_EQUALS("", errout_str());

functionVariableUsage("void f(const std::vector<int>& v) {\n" // #13303
" std::vector<int>::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
Expand Down
Loading