File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ()) {
You can’t perform that action at this time.
0 commit comments