Fixed #3594 (false positive: returning reference to auto variable)
This commit is contained in:
parent
4f1f6e1824
commit
abcbe2e49f
|
@ -260,9 +260,9 @@ void CheckAutoVariables::returnReference()
|
|||
|
||||
if (var1 && var1->isLocal() && !var1->isStatic()) {
|
||||
// If reference variable is used, check what it references
|
||||
if (Token::Match(var1->nameToken(), "%var% =")) {
|
||||
if (Token::Match(var1->nameToken(), "%var% [=(]")) {
|
||||
const Token *tok3 = var1->nameToken()->tokAt(2);
|
||||
if (!Token::Match(tok3, "%var% [;.]"))
|
||||
if (!Token::Match(tok3, "%var% [);.]"))
|
||||
continue;
|
||||
|
||||
// Only report error if variable that is referenced is
|
||||
|
|
|
@ -87,6 +87,7 @@ private:
|
|||
TEST_CASE(returnReference3);
|
||||
TEST_CASE(returnReference4);
|
||||
TEST_CASE(returnReference5);
|
||||
TEST_CASE(returnReference6);
|
||||
|
||||
// return c_str()..
|
||||
TEST_CASE(returncstr);
|
||||
|
@ -520,6 +521,14 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void returnReference6() {
|
||||
check("Fred & create() {\n"
|
||||
" Fred &fred(*new Fred);\n"
|
||||
" return fred;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void returncstr() {
|
||||
check("std::string hello()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue