llvm-project/clang/test/Analysis/issue-91835.cpp
flovent b55dd8f607
[clang][analyzer] Correctly handle structured bindings captured by lambda (#132579)
this PR fixes #91835.

For `DeclRefExpr` in lambda's function body, it will references to
original variable declaration in AST rather than `FieldDecl` for lambda
class, so it's needed to find the corresponding `FieldDecl` and bind
`DeclRefExpr`'s value to it.

This is already implemented for variables that are not in a structured
binding structure, so I extracted that part of the code so that it can
be used in the structured binding case.
2025-03-26 16:03:43 +01:00

16 lines
288 B
C++

// RUN: %clang_analyze_cc1 -std=c++20 %s -analyzer-checker=core.NullDereference -analyzer-output=text -verify
// expected-no-diagnostics
struct S { int x; };
void f(int x) { (void)x; }
int main()
{
S s{42};
auto& [x] = s;
auto g = [x](){ f(x); }; // no warning
g();
}