Closed as not planned
Description
struct Foo {
int first;
int second;
};
void bar() {
Foo f;
auto &[first, second] = f;
auto works1 = [&first]() { (void) first; };
auto works2 = [&]() { (void) first; };
auto bug1 = [&first](auto arg) { (void) first; }; // -Wunused-lambda-capture
auto bug2 = [&](auto arg) { (void) first; }; // error: reference to local binding 'first' declared in enclosing function 'bar'
works1();
works2();
bug1(42);
bug2(42);
}
https://godbolt.org/z/zzqdf9sa8
When a generic lambda attempts to capture a structured binding (legal since c++20), clang either emits an unused-lambda-capture
warning for explicit structured binding captures, or it fails to compile if the structured binding is used in a generic lambda with an implicit default capture.