diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 862336611..e4869c7ed 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3253,7 +3253,7 @@ static void valueFlowForwardLifetime(Token * tok, TokenList *tokenlist, ErrorLog return; } Token *parent = tok->astParent(); - while (parent && (parent->isArithmeticalOp() || parent->str() == ",")) + while (parent && parent->str() == ",") parent = parent->astParent(); if (!parent) return; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 83ee2487d..614401126 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -2421,6 +2421,17 @@ private: " }\n" "};\n"); ASSERT_EQUALS("", errout.str()); + + check("int f() {\n" + " int i;\n" + " {\n" + " std::vector vec;\n" + " const auto iter = vec.begin();\n" + " i = (int)(iter - vec.begin());\n" + " }\n" + " return i;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void danglingLifetime() {