Fix issue 9853: False positive: returnReference when using a pointer to container (#2765)
This commit is contained in:
parent
12d51ae5c4
commit
03cefd5d70
|
@ -3063,7 +3063,7 @@ std::vector<LifetimeToken> getLifetimeTokens(const Token* tok, ValueFlow::Value:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} else if (Token::Match(tok->tokAt(-2), ". %name% (") && astIsContainer(tok->tokAt(-2)->astOperand1())) {
|
} else if (Token::Match(tok->tokAt(-2), ". %name% (") && tok->tokAt(-2)->originalName() != "->" && astIsContainer(tok->tokAt(-2)->astOperand1())) {
|
||||||
const Library::Container* library = getLibraryContainer(tok->tokAt(-2)->astOperand1());
|
const Library::Container* library = getLibraryContainer(tok->tokAt(-2)->astOperand1());
|
||||||
Library::Container::Yield y = library->getYield(tok->previous()->str());
|
Library::Container::Yield y = library->getYield(tok->previous()->str());
|
||||||
if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM) {
|
if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM) {
|
||||||
|
|
|
@ -2143,6 +2143,13 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n", errout.str());
|
||||||
|
|
||||||
|
check("std::vector<int>* g();\n"
|
||||||
|
"int& f() {\n"
|
||||||
|
" auto* p = g();\n"
|
||||||
|
" return p->front();\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("std::vector<std::vector<int>> g();\n"
|
check("std::vector<std::vector<int>> g();\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" for(auto& x:g())\n"
|
" for(auto& x:g())\n"
|
||||||
|
|
Loading…
Reference in New Issue