@@ -1207,45 +1207,46 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
12071207 return x.token < y.token ;
12081208 }
12091209 };
1210- SmallVector<ReferenceToken> refs_result;
12111210 if (!tok)
1212- return refs_result ;
1211+ return {} ;
12131212 if (depth < 0 ) {
1213+ SmallVector<ReferenceToken> refs_result;
12141214 refs_result.push_back ({tok, std::move (errors)});
12151215 return refs_result;
12161216 }
12171217 const Variable *var = tok->variable ();
12181218 if (var && var->declarationId () == tok->varId ()) {
12191219 if (var->nameToken () == tok || isStructuredBindingVariable (var)) {
1220+ SmallVector<ReferenceToken> refs_result;
12201221 refs_result.push_back ({tok, std::move (errors)});
12211222 return refs_result;
12221223 }
12231224 if (var->isReference () || var->isRValueReference ()) {
12241225 const Token * const varDeclEndToken = var->declEndToken ();
12251226 if (!varDeclEndToken) {
1227+ SmallVector<ReferenceToken> refs_result;
12261228 refs_result.push_back ({tok, std::move (errors)});
12271229 return refs_result;
12281230 }
12291231 if (var->isArgument ()) {
12301232 errors.emplace_back (varDeclEndToken, " Passed to reference." );
1233+ SmallVector<ReferenceToken> refs_result;
12311234 refs_result.push_back ({tok, std::move (errors)});
12321235 return refs_result;
12331236 }
12341237 if (Token::simpleMatch (varDeclEndToken, " =" )) {
12351238 if (astHasToken (varDeclEndToken, tok))
1236- return refs_result ;
1239+ return {} ;
12371240 errors.emplace_back (varDeclEndToken, " Assigned to reference." );
12381241 const Token *vartok = varDeclEndToken->astOperand2 ();
12391242 if (vartok == tok || (!temporary && isTemporary (true , vartok, nullptr , true ) &&
12401243 (var->isConst () || var->isRValueReference ()))) {
1244+ SmallVector<ReferenceToken> refs_result;
12411245 refs_result.push_back ({tok, std::move (errors)});
12421246 return refs_result;
12431247 }
12441248 if (vartok)
12451249 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;
12491250 }
12501251 }
12511252 } else if (Token::simpleMatch (tok, " ?" ) && Token::simpleMatch (tok->astOperand2 (), " :" )) {
@@ -1258,18 +1259,21 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
12581259 result.insert (refs.cbegin (), refs.cend ());
12591260
12601261 if (!inconclusive && result.size () != 1 ) {
1262+ SmallVector<ReferenceToken> refs_result;
12611263 refs_result.push_back ({tok, std::move (errors)});
12621264 return refs_result;
12631265 }
12641266
12651267 if (!result.empty ()) {
1268+ SmallVector<ReferenceToken> refs_result;
12661269 refs_result.insert (refs_result.end (), result.cbegin (), result.cend ());
12671270 return refs_result;
12681271 }
12691272
12701273 } else if (tok->previous () && tok->previous ()->function () && Token::Match (tok->previous (), " %name% (" )) {
12711274 const Function *f = tok->previous ()->function ();
12721275 if (!Function::returnsReference (f)) {
1276+ SmallVector<ReferenceToken> refs_result;
12731277 refs_result.push_back ({tok, std::move (errors)});
12741278 return refs_result;
12751279 }
@@ -1282,17 +1286,20 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
12821286 followAllReferences (returnTok, temporary, inconclusive, errors, depth - returns.size ())) {
12831287 const Variable* argvar = rt.token ->variable ();
12841288 if (!argvar) {
1289+ SmallVector<ReferenceToken> refs_result;
12851290 refs_result.push_back ({tok, std::move (errors)});
12861291 return refs_result;
12871292 }
12881293 if (argvar->isArgument () && (argvar->isReference () || argvar->isRValueReference ())) {
12891294 const int n = getArgumentPos (argvar, f);
12901295 if (n < 0 ) {
1296+ SmallVector<ReferenceToken> refs_result;
12911297 refs_result.push_back ({tok, std::move (errors)});
12921298 return refs_result;
12931299 }
12941300 std::vector<const Token*> args = getArguments (tok->previous ());
12951301 if (n >= args.size ()) {
1302+ SmallVector<ReferenceToken> refs_result;
12961303 refs_result.push_back ({tok, std::move (errors)});
12971304 return refs_result;
12981305 }
@@ -1304,17 +1311,20 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
13041311 followAllReferences (argTok, temporary, inconclusive, std::move (er), depth - returns.size ());
13051312 result.insert (refs.cbegin (), refs.cend ());
13061313 if (!inconclusive && result.size () > 1 ) {
1314+ SmallVector<ReferenceToken> refs_result;
13071315 refs_result.push_back ({tok, std::move (errors)});
13081316 return refs_result;
13091317 }
13101318 }
13111319 }
13121320 }
13131321 if (!result.empty ()) {
1322+ SmallVector<ReferenceToken> refs_result;
13141323 refs_result.insert (refs_result.end (), result.cbegin (), result.cend ());
13151324 return refs_result;
13161325 }
13171326 }
1327+ SmallVector<ReferenceToken> refs_result;
13181328 refs_result.push_back ({tok, std::move (errors)});
13191329 return refs_result;
13201330}
0 commit comments