diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 86cc5c01b..746ed1f35 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3063,7 +3063,7 @@ std::vector getLifetimeTokens(const Token* tok, ValueFlow::Value: } } 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()); Library::Container::Yield y = library->getYield(tok->previous()->str()); if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM) { diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 7d5320c88..059d15064 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -2143,6 +2143,13 @@ private: "}\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()); + check("std::vector* g();\n" + "int& f() {\n" + " auto* p = g();\n" + " return p->front();\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + check("std::vector> g();\n" "void f() {\n" " for(auto& x:g())\n"