From 120c30a4f0864467f25686142086470f8a4d3b0c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 19 Feb 2026 15:06:38 +0100 Subject: [PATCH 1/2] Update valueflow.cpp --- lib/valueflow.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index ec90fb3e302..94dde440368 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5958,9 +5958,12 @@ static Token* findStartToken(const Variable* var, Token* start, const Library& l })) return first->previous(); // Compute the outer scope - while (scope && scope->nestedIn != var->scope()) + while (scope && scope->nestedIn != var->scope()) { + if (scope->type == ScopeType::eLambda && !Token::simpleMatch(scope->bodyEnd, "} (")) + return start; scope = scope->nestedIn; - if (!scope) + } + if (!scope || (scope->type == ScopeType::eLambda && !Token::simpleMatch(scope->bodyEnd, "} ("))) return start; auto* tok = const_cast(scope->bodyStart); if (!tok) From 4d6cbf15e4029ac00b45c93690607e4407a47d8c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 19 Feb 2026 15:08:23 +0100 Subject: [PATCH 2/2] Update testuninitvar.cpp --- test/testuninitvar.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 15467db7971..ad9dee0fcac 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -6663,6 +6663,26 @@ class TestUninitVar : public TestFixture { " return ret;\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + valueFlowUninit("int f() {\n" // #12944 + " int i;\n" + " auto x = [&]() { return i; };\n" + " i = 5;\n" + " return x();\n" + "}\n" + "int g() {\n" + " int i;\n" + " {\n" + " auto x = [&]() { return i; };\n" + " i = 5;\n" + " return x();\n" + " }\n" + "}\n" + "int h() {\n" + " int j;\n" + " return [&]() { return j; }();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:17:27]: (error) Uninitialized variable: j [uninitvar]\n", errout_str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value