https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67274
Bug ID: 67274 Summary: Inconsistent `this->` required when calling member function in a lambda capturing `this` through another function Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vittorio.romeo at outlook dot com Target Milestone: --- Passing a `this`-capturing generic lambda (to a template function) that calls a member function of `this` without an explicit `this->` results in an error: error: cannot call member function 'void Example::foo(int)' without object call([this](auto x){ foo(x); });` If the lambda is not generic, or if the lambda is not passed to any other function but called in place, it compiles without an explicit `this->`. For reference, clang 3.6+ is cool with the code in all situations. --- Minimal example: http://melpon.org/wandbox/permlink/M2eH3FUOentPfieM template<typename TF> void call(TF&& f) { f(1); } struct Example { void foo(int){ } void bar() { call([this](auto x){ foo(x); }); } }; int main() { Example{}.bar(); return 0; } --- StackOverflow question with more examples: http://stackoverflow.com/questions/32097759