Fix ValueFlow crash (#4461)

This commit is contained in:
chrchr-github 2022-09-13 12:25:15 +02:00 committed by GitHub
parent 3887d6dde1
commit e904f7341e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -4818,8 +4818,10 @@ static void valueFlowAfterMove(TokenList* tokenlist, SymbolDatabase* symboldatab
value.setKnown();
setTokenValue(tok, value, settings);
const Token * const endOfVarScope = var->scope()->bodyEnd;
if (var->scope()) {
const Token* const endOfVarScope = var->scope()->bodyEnd;
valueFlowForward(tok->next(), endOfVarScope, tok, std::move(value), tokenlist);
}
continue;
}
ValueFlow::Value::MoveKind moveKind;

View File

@ -6789,6 +6789,15 @@ private:
" for (b c : {b{}, {}}) {}\n"
"}\n";
valueOfTok(code, "c");
code = "class T {\n"
"private slots:\n"
" void f() { D& r = dynamic_cast<D&>(*m); }\n"
" void g() { m.reset(new D); }\n"
"private:\n"
" std::shared_ptr<B> m;\n"
"};\n";
valueOfTok(code, "r");
}
void valueFlowHang() {