From 7ce17f076a5fa25fd6caeaffcd59188f6ad34570 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 31 Aug 2021 02:48:23 -0500 Subject: [PATCH] Fix 10318: iterator converted to type, wrong scope check (#3433) --- lib/valueflow.cpp | 2 +- test/testautovariables.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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() {