Fix issue 9458: Crash with shadow variables in a lambda (#2406)

* Fix issue 9458: Crash with shadow variables in a lambda

* Format
This commit is contained in:
Paul Fultz II 2019-11-29 02:45:02 -06:00 committed by orbitcowboy
parent f554a71dea
commit f9d33c07f8
2 changed files with 11 additions and 3 deletions

View File

@ -1665,9 +1665,9 @@ static void valueFlowReverse(TokenList *tokenlist,
const Token * const startToken = var->nameToken();
for (Token *tok2 = tok->previous(); ; tok2 = tok2->previous()) {
if (!tok2 ||
tok2 == startToken ||
(tok2->str() == "{" && tok2->scope()->type == Scope::ScopeType::eFunction)) {
if (!tok2 || tok2 == startToken ||
(tok2->str() == "{" &&
(tok2->scope()->type == Scope::ScopeType::eFunction || tok2->scope()->type == Scope::ScopeType::eLambda))) {
break;
}

View File

@ -4334,6 +4334,14 @@ private:
" state = x;\n"
"}\n";
valueOfTok(code, "=");
code = "void a() {\n"
" auto b = [b = 0] {\n"
" if (b) {\n"
" }\n"
" };\n"
"}\n";
valueOfTok(code, "0");
}
};