https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85889
Bug ID: 85889 Summary: lambda expression can capture structured bindings Product: gcc Version: 8.1.1 Status: UNCONFIRMED Keywords: accepts-invalid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- [expr.prim.lambda.capture] p8 says "If a lambda-expression explicitly captures an entity that is not odr-usable or captures a structured binding (explicitly or implicitly), the program is ill-formed." With -std=c++17 this compiles without any diagnostic: struct X { int i, j; }; void f() { X x{}; auto [i, j] = x; [&i]() { }; } Clang says: l.cc:5:5: error: 'i' in capture list does not name a variable [&i]() { }; ^ l.cc:5:3: warning: expression result unused [-Wunused-value] [&i]() { }; ^~~~~~~~~~ 1 warning and 1 error generated. And EDG says: "l.cc", line 5: error: structured binding cannot be captured [&i]() { }; ^ "l.cc", line 4: warning: variable "i" was declared but never referenced auto [i, j] = x; ^ "l.cc", line 4: warning: variable "j" was declared but never referenced auto [i, j] = x; ^ 1 error detected in the compilation of "l.cc".