Fix FP when returning a pointer to a container (#3379)
This commit is contained in:
parent
28c8b00e5c
commit
4626f9ed76
|
@ -2838,7 +2838,8 @@ static std::vector<LifetimeToken> getLifetimeTokens(const Token* tok,
|
|||
if (!vartok)
|
||||
return {{tok, std::move(errorPath)}};
|
||||
const Variable *tokvar = vartok->variable();
|
||||
if (!isUniqueSmartPointer(vartok) && !astIsContainer(vartok) &&
|
||||
const bool isContainer = astIsContainer(vartok) && !astIsPointer(vartok);
|
||||
if (!isUniqueSmartPointer(vartok) && !isContainer &&
|
||||
!(tokvar && tokvar->isArray() && !tokvar->isArgument()) &&
|
||||
(Token::Match(vartok->astParent(), "[|*") || vartok->astParent()->originalName() == "->")) {
|
||||
for (const ValueFlow::Value &v : vartok->values()) {
|
||||
|
|
|
@ -118,6 +118,7 @@ private:
|
|||
TEST_CASE(returnReference20); // #9536
|
||||
TEST_CASE(returnReference21); // #9530
|
||||
TEST_CASE(returnReference22);
|
||||
TEST_CASE(returnReference23);
|
||||
TEST_CASE(returnReferenceFunction);
|
||||
TEST_CASE(returnReferenceContainer);
|
||||
TEST_CASE(returnReferenceLiteral);
|
||||
|
@ -1451,6 +1452,14 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:4]: (error) Reference to local variable returned.\n", errout.str());
|
||||
}
|
||||
|
||||
void returnReference23() {
|
||||
check("const std::vector<int> * g();\n"
|
||||
"const std::vector<int>& f() {\n"
|
||||
" return *g();\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void returnReferenceFunction() {
|
||||
check("int& f(int& a) {\n"
|
||||
" return a;\n"
|
||||
|
|
Loading…
Reference in New Issue