Fix 8872: Crash in LifetimeStore when there is no scope for variable

This fixes crash in:

```cpp
struct edit_line_paste_over {
    void operator()(agi::Context *c) override {
        paste_lines(c, true, [&](AssDialogue *new_line) -> AssDialogue * {
            AssDialogue *ret = paste_over(c->parent, pasteOverOptions, new_line, static_cast<AssDialogue*>(&*pos));
            return ret;
          });
    }
};
```
This commit is contained in:
Paul Fultz II 2018-12-01 19:11:26 +01:00 committed by Daniel Marjamäki
parent 67dd822910
commit b841b818d2
2 changed files with 35 additions and 0 deletions

View File

@ -2751,6 +2751,8 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
auto isCapturingVariable = [&](const Variable *var) {
const Scope *scope = var->scope();
if (!scope)
return false;
if (scopes.count(scope) > 0)
return false;
if (scope->isNestedIn(bodyScope))

View File

@ -1510,6 +1510,7 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
<<<<<<< HEAD
<<<<<<< HEAD
check("void f() {\n"
" struct b {\n"
@ -1540,6 +1541,38 @@ private:
" A &&a = T{1, 2, 3}[1]();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
=======
// Make sure we dont hang
check("struct A;\n"
"void f() {\n"
" using T = A[3];\n"
" A &&a = T{1, 2, 3}[1];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// Make sure we dont hang
check("struct A;\n"
"void f() {\n"
" using T = A[3];\n"
" A &&a = T{1, 2, 3}[1]();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// Crash #8872
check("struct a {\n"
" void operator()(b c) override {\n"
" d(c, [&] { c->e });\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
check("struct a {\n"
" void operator()(b c) override {\n"
" d(c, [=] { c->e });\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
>>>>>>> 6586f2d354d3f9dc26d830b6e641f158a5c58432
}
void danglingLifetimeFunction() {