@@ -1207,45 +1207,46 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
1207
1207
return x.token < y.token ;
1208
1208
}
1209
1209
};
1210
- SmallVector<ReferenceToken> refs_result;
1211
1210
if (!tok)
1212
- return refs_result ;
1211
+ return {} ;
1213
1212
if (depth < 0 ) {
1213
+ SmallVector<ReferenceToken> refs_result;
1214
1214
refs_result.push_back ({tok, std::move (errors)});
1215
1215
return refs_result;
1216
1216
}
1217
1217
const Variable *var = tok->variable ();
1218
1218
if (var && var->declarationId () == tok->varId ()) {
1219
1219
if (var->nameToken () == tok || isStructuredBindingVariable (var)) {
1220
+ SmallVector<ReferenceToken> refs_result;
1220
1221
refs_result.push_back ({tok, std::move (errors)});
1221
1222
return refs_result;
1222
1223
}
1223
1224
if (var->isReference () || var->isRValueReference ()) {
1224
1225
const Token * const varDeclEndToken = var->declEndToken ();
1225
1226
if (!varDeclEndToken) {
1227
+ SmallVector<ReferenceToken> refs_result;
1226
1228
refs_result.push_back ({tok, std::move (errors)});
1227
1229
return refs_result;
1228
1230
}
1229
1231
if (var->isArgument ()) {
1230
1232
errors.emplace_back (varDeclEndToken, " Passed to reference." );
1233
+ SmallVector<ReferenceToken> refs_result;
1231
1234
refs_result.push_back ({tok, std::move (errors)});
1232
1235
return refs_result;
1233
1236
}
1234
1237
if (Token::simpleMatch (varDeclEndToken, " =" )) {
1235
1238
if (astHasToken (varDeclEndToken, tok))
1236
- return refs_result ;
1239
+ return {} ;
1237
1240
errors.emplace_back (varDeclEndToken, " Assigned to reference." );
1238
1241
const Token *vartok = varDeclEndToken->astOperand2 ();
1239
1242
if (vartok == tok || (!temporary && isTemporary (true , vartok, nullptr , true ) &&
1240
1243
(var->isConst () || var->isRValueReference ()))) {
1244
+ SmallVector<ReferenceToken> refs_result;
1241
1245
refs_result.push_back ({tok, std::move (errors)});
1242
1246
return refs_result;
1243
1247
}
1244
1248
if (vartok)
1245
1249
return followAllReferences (vartok, temporary, inconclusive, std::move (errors), depth - 1 );
1246
- } else {
1247
- refs_result.push_back ({tok, std::move (errors)});
1248
- return refs_result;
1249
1250
}
1250
1251
}
1251
1252
} else if (Token::simpleMatch (tok, " ?" ) && Token::simpleMatch (tok->astOperand2 (), " :" )) {
@@ -1258,18 +1259,21 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
1258
1259
result.insert (refs.cbegin (), refs.cend ());
1259
1260
1260
1261
if (!inconclusive && result.size () != 1 ) {
1262
+ SmallVector<ReferenceToken> refs_result;
1261
1263
refs_result.push_back ({tok, std::move (errors)});
1262
1264
return refs_result;
1263
1265
}
1264
1266
1265
1267
if (!result.empty ()) {
1268
+ SmallVector<ReferenceToken> refs_result;
1266
1269
refs_result.insert (refs_result.end (), result.cbegin (), result.cend ());
1267
1270
return refs_result;
1268
1271
}
1269
1272
1270
1273
} else if (tok->previous () && tok->previous ()->function () && Token::Match (tok->previous (), " %name% (" )) {
1271
1274
const Function *f = tok->previous ()->function ();
1272
1275
if (!Function::returnsReference (f)) {
1276
+ SmallVector<ReferenceToken> refs_result;
1273
1277
refs_result.push_back ({tok, std::move (errors)});
1274
1278
return refs_result;
1275
1279
}
@@ -1282,17 +1286,20 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
1282
1286
followAllReferences (returnTok, temporary, inconclusive, errors, depth - returns.size ())) {
1283
1287
const Variable* argvar = rt.token ->variable ();
1284
1288
if (!argvar) {
1289
+ SmallVector<ReferenceToken> refs_result;
1285
1290
refs_result.push_back ({tok, std::move (errors)});
1286
1291
return refs_result;
1287
1292
}
1288
1293
if (argvar->isArgument () && (argvar->isReference () || argvar->isRValueReference ())) {
1289
1294
const int n = getArgumentPos (argvar, f);
1290
1295
if (n < 0 ) {
1296
+ SmallVector<ReferenceToken> refs_result;
1291
1297
refs_result.push_back ({tok, std::move (errors)});
1292
1298
return refs_result;
1293
1299
}
1294
1300
std::vector<const Token*> args = getArguments (tok->previous ());
1295
1301
if (n >= args.size ()) {
1302
+ SmallVector<ReferenceToken> refs_result;
1296
1303
refs_result.push_back ({tok, std::move (errors)});
1297
1304
return refs_result;
1298
1305
}
@@ -1304,17 +1311,20 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
1304
1311
followAllReferences (argTok, temporary, inconclusive, std::move (er), depth - returns.size ());
1305
1312
result.insert (refs.cbegin (), refs.cend ());
1306
1313
if (!inconclusive && result.size () > 1 ) {
1314
+ SmallVector<ReferenceToken> refs_result;
1307
1315
refs_result.push_back ({tok, std::move (errors)});
1308
1316
return refs_result;
1309
1317
}
1310
1318
}
1311
1319
}
1312
1320
}
1313
1321
if (!result.empty ()) {
1322
+ SmallVector<ReferenceToken> refs_result;
1314
1323
refs_result.insert (refs_result.end (), result.cbegin (), result.cend ());
1315
1324
return refs_result;
1316
1325
}
1317
1326
}
1327
+ SmallVector<ReferenceToken> refs_result;
1318
1328
refs_result.push_back ({tok, std::move (errors)});
1319
1329
return refs_result;
1320
1330
}
0 commit comments