https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89995
Bug ID: 89995 Summary: Misleading error message 'this' was not captured for this lambda function Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gabriel.aubut-lussier at outlook dot com Target Milestone: --- The error message given when 'this' cannot be captured is misleading in the sense that it points the user to the lambda that fails to capture 'this' rather than raise questions about why it fails to do so. The icc compiler does the best job of giving context with this error. MSVC also displays a bit more information. Clang has the worst offender. GCC could use a bit of improvement. Aiming for an error message that is closer to icc seems like the ideal solution. The error message given by icc is the following: error: this enclosing-function local variable cannot be referenced in this lambda body because an enclosing lambda does not allow implicit captures Godbolt : https://gcc.godbolt.org/z/rmefHT Sample code for the issue: struct S { void f() { []() { [this]() { }(); }(); } }; int main() { S s; s.f(); }