File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -231,9 +231,31 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) const
231231{
232232 if (!Token::Match (tok, " return %var% (" ))
233233 return false ;
234- // TODO: Find all functions that return objects by value
235- return bool (NULL != Token::findmatch (_tokenizer->tokens (), (" std :: string " + tok->next ()->str () + " (" ).c_str ()) &&
236- NULL == Token::findmatch (_tokenizer->tokens (), (" std :: string & " + tok->next ()->str () + " (" ).c_str ()));
234+
235+ const std::string &funcname (tok->next ()->str ());
236+
237+ const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase ();
238+
239+ std::list<Scope>::const_iterator scope;
240+
241+ bool retref = false ; // is there such a function that returns a reference?
242+ bool retvalue = false ; // is there such a function that returns a value?
243+
244+ for (scope = symbolDatabase->scopeList .begin (); scope != symbolDatabase->scopeList .end (); ++scope) {
245+ if (scope->type == Scope::eFunction) {
246+ if (scope->classDef ->str () == funcname) {
247+ const Token *tok2 = scope->classDef ;
248+ while (tok2 && Token::Match (tok2->tokAt (-2 ), " %type% ::" ))
249+ tok2 = tok2->tokAt (-2 );
250+ if (tok2 && Token::simpleMatch (tok2->tokAt (-3 ), " std :: string" ))
251+ retvalue = true ;
252+ else if (tok2 && Token::simpleMatch (tok2->tokAt (-4 ), " std :: string &" ))
253+ retref = true ;
254+ }
255+ }
256+ }
257+
258+ return bool (!retref && retvalue);
237259}
238260
239261// ---------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments