https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106330
Bug ID: 106330 Summary: Unknown type leads to error messages about missing lambda capture Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: drahflow at gmx dot de Target Milestone: --- Running g++ on void unhelpful(int i) { Unknown u; u.distract(); for(auto &i: u) { [i]() { unhelpful(i); }; } } outputs test.c++: In function 'void unhelpful(int)': test.c++:2:5: error: 'Unknown' was not declared in this scope 2 | Unknown u; | ^~~~~~~ test.c++:3:5: error: 'u' was not declared in this scope 3 | u.distract(); | ^ test.c++: In lambda function: test.c++:7:23: error: 'i' is not captured 7 | unhelpful(i); | ^ test.c++:6:11: note: the lambda has no capture-default 6 | [i]() { | ^ test.c++:5:15: note: '<typeprefixerror>i' declared here 5 | for(auto &i: u) { | ^ Compiler returned: 1 The error message for line 7 together with the two notes are quite unhelpful. (Of course the example where I encountered the problem had a lot more code between u.distract() and for(auto &i: u) ... )