diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 8ccb845b1..29f8b8b35 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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)) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index b69a6d75d..89c7f55a3 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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() {