Skip to content

Commit

Permalink
add check for range based for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ludviggunne committed Jan 9, 2025
1 parent c727c82 commit 571eef6
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1540,15 +1540,29 @@ void CheckUnusedVar::checkStructMemberUsage()
continue;

const Token *tok = var->nameToken()->linkAt(-1);
if (!Token::Match(tok, "] %assign%"))
continue;
if (Token::Match(tok, "] %assign%"))
{
tok = tok->next()->astOperand2();
const ValueType *valueType = tok->valueType();

tok = tok->next()->astOperand2();
const ValueType *valueType = tok->valueType();
if (valueType && valueType->typeScope == &scope) {
bailout = true;
break;
}
}

if (valueType && valueType->typeScope == &scope) {
bailout = true;
break;
if (Token::Match(tok, "] :")) {
tok = tok->next()->astOperand2();
const ValueType *valueType = tok->valueType();

if (!valueType->containerTypeToken)
continue;

const Type *type = valueType->containerTypeToken->type();
if (type && type->classScope == &scope) {
bailout = true;
break;
}
}
}
if (bailout)
Expand Down

0 comments on commit 571eef6

Please sign in to comment.