Fixed #3791 (False positive: returnTempReference)
This commit is contained in:
parent
826d5bb00b
commit
17c27f51ff
|
@ -232,7 +232,8 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) const
|
|||
if (!Token::Match(tok, "return %var% ("))
|
||||
return false;
|
||||
// TODO: Find all functions that return objects by value
|
||||
return bool(NULL != Token::findmatch(_tokenizer->tokens(), ("std :: string " + tok->next()->str() + " (").c_str()));
|
||||
return bool(NULL != Token::findmatch(_tokenizer->tokens(), ("std :: string " + tok->next()->str() + " (").c_str()) &&
|
||||
NULL == Token::findmatch(_tokenizer->tokens(), ("std :: string & " + tok->next()->str() + " (").c_str()));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -88,6 +88,7 @@ private:
|
|||
TEST_CASE(returnReference4);
|
||||
TEST_CASE(returnReference5);
|
||||
TEST_CASE(returnReference6);
|
||||
TEST_CASE(returnReference7);
|
||||
|
||||
// return c_str()..
|
||||
TEST_CASE(returncstr);
|
||||
|
@ -552,6 +553,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void returnReference7() { // 3791 - false positive for overloaded function
|
||||
check("std::string a();\n"
|
||||
"std::string &a(int);\n"
|
||||
"std::string &b() {\n"
|
||||
" return a(12);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void returncstr() {
|
||||
check("std::string hello()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue