Skip to content

Commit faddc5f

Browse files
committed
fix #13269
1 parent 11070a8 commit faddc5f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

lib/checkunusedvar.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,13 @@ void CheckUnusedVar::checkFunctionVariableUsage()
11861186
const Token* lambdaOrInlineStart{};
11871187
const bool hasLambdaOrInline = scope->hasInlineOrLambdaFunction(&lambdaOrInlineStart);
11881188

1189+
const Token *nextStructuredBindingTok = nullptr;
1190+
11891191
for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
1192+
if (nextStructuredBindingTok)
1193+
tok = nextStructuredBindingTok;
1194+
nextStructuredBindingTok = nullptr;
1195+
11901196
if (findLambdaEndToken(tok))
11911197
// todo: handle lambdas
11921198
break;
@@ -1196,6 +1202,15 @@ void CheckUnusedVar::checkFunctionVariableUsage()
11961202
const Token *varDecl = nullptr;
11971203
if (tok->variable() && tok->variable()->nameToken() == tok) {
11981204
const Token * eq = tok->next();
1205+
if (isStructuredBindingVariable(tok->variable())) {
1206+
while (!Token::simpleMatch(eq, "]")) {
1207+
eq = eq->next();
1208+
if (eq->variable() && !nextStructuredBindingTok)
1209+
nextStructuredBindingTok = eq;
1210+
}
1211+
if (eq)
1212+
eq = eq->next();
1213+
}
11991214
while (Token::simpleMatch(eq, "["))
12001215
eq = eq->link()->next();
12011216
if (Token::simpleMatch(eq, ") (") && Token::simpleMatch(eq->linkAt(1), ") ="))

0 commit comments

Comments
 (0)