diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 53f924741..effb2d539 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2935,8 +2935,10 @@ static std::vector getLifetimeTokens(const Token* tok, if (vartok == tok) return {{tok, true, std::move(errorPath)}}; const Token* contok = var->nameToken()->astParent()->astOperand2(); - if (contok) + if (astIsContainer(contok)) return getLifetimeTokens(contok, escape, std::move(errorPath), pred, depth - 1); + else + return std::vector{}; } else { return std::vector {}; } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index f4087693a..bf6b6d311 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -2432,6 +2432,15 @@ private: " return i;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("int* get(std::vector& container) {\n" + " Sequence seq(container);\n" + " for (auto& r : seq) {\n" + " return &r;\n" + " }\n" + " return &*seq.begin();\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void danglingLifetime() {