Skip to content

Commit bca983d

Browse files
committed
fix
1 parent 6ec676f commit bca983d

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

lib/checkunusedvar.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,9 +1265,41 @@ void CheckUnusedVar::checkFunctionVariableUsage()
12651265
if (isIncrementOrDecrement && tok->astParent() && precedes(tok, tok->astOperand1()))
12661266
continue;
12671267

1268-
if (tok->str() == "=" && !(tok->valueType() && tok->valueType()->pointer) && isRaiiClass(tok->valueType(), tok->isCpp(), false))
1268+
const auto raiiNonPtr = [](const Token *tok) {
1269+
return !(tok->valueType() && tok->valueType()->pointer) && isRaiiClass(tok->valueType(), tok->isCpp(), false);
1270+
};
1271+
1272+
if (tok->str() == "=" && raiiNonPtr(tok))
12691273
continue;
12701274

1275+
if (Token::Match(tok, "%var% {") && tok->next()->isCpp11init() == Token::Cpp11init::CPP11INIT) {
1276+
const Token *child = tok->next()->astOperand2();
1277+
bool hasRaiiMember = false;
1278+
1279+
while (child) {
1280+
const Token *entry = nullptr;
1281+
if (Token::simpleMatch(child, ",")) {
1282+
entry = child->astOperand1();
1283+
child = child->astOperand2();
1284+
} else {
1285+
entry = child;
1286+
}
1287+
1288+
if (raiiNonPtr(entry)) {
1289+
hasRaiiMember = true;
1290+
break;
1291+
}
1292+
1293+
if (entry == child) {
1294+
break;
1295+
}
1296+
}
1297+
1298+
if (hasRaiiMember) {
1299+
continue;
1300+
}
1301+
}
1302+
12711303
const bool isPointer = tok->valueType() && (tok->valueType()->pointer || tok->valueType()->type == ValueType::SMART_POINTER);
12721304

12731305
if (tok->isName()) {

0 commit comments

Comments
 (0)