Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token*>(scope->bodyStart);
if (!tok)
Expand Down
20 changes: 20 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading