https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105869
Bug ID: 105869 Summary: Use of this inside a lambda not inside a non-static method gives an interesting message Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` auto t = []() { this; }; ``` Currently GCC gives: ``` <source>:1:17: error: 'this' was not captured for this lambda function 1 | auto t = []() { this; }; | ^~~~ ``` Except there is no this to capture and if you try to capture it, GCC gives: ``` <source>:1:11: error: invalid use of 'this' at top level 1 | auto t = [this]() { this; }; | ^~~~ <source>: In lambda function: <source>:1:21: error: 'this' was not captured for this lambda function 1 | auto t = [this]() { this; }; | ^~~~ ``` Clang gives a clearer error message: ``` <source>:1:17: error: invalid use of 'this' outside of a non-static member function auto t = []() { this; }; ^ ```