Fix 10318: iterator converted to type, wrong scope check (#3433)

This commit is contained in:
Paul Fultz II 2021-08-31 02:48:23 -05:00 committed by GitHub
parent 15eb53b403
commit 7ce17f076a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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;

View File

@ -2421,6 +2421,17 @@ private:
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
check("int f() {\n"
" int i;\n"
" {\n"
" std::vector<int> 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() {