This code is okay(gets a error): http://liveworkspace.org/code/1110068f996076a08d835ab18789c034 App crash: http://liveworkspace.org/code/3d5e51c9059ea4f37ce2d0d23739d374 Minimal testcase: http://liveworkspace.org/code/30fd3222a9650d68b7f9746754e86f03
> App crash: > http://liveworkspace.org/code/3d5e51c9059ea4f37ce2d0d23739d374 More detailed output. source: #include <stdio.h> typedef void(*void_func)(); void foo(void_func f) { f(); } class C { public: template<typename F> void bar(F f) { auto func = [f, this] { f(); printf("%d!!!\n", k); }; foo(func); } private: int k = 10; }; int main() { printf("%s\n", "ping1"); auto func = [] { printf("called\n"); }; printf("%s\n", "ping2"); C().bar(func); printf("%s\n", "ping3"); } run: $ g++-4.7.2 -std=c++11 ice.cpp -oice && ./ice ping1 ping2 called Segmentation fault (core dumped)
May be duplicate of other known issues about lambdas vs templates.
I think the code should be rejected. Possibly related to Bug 55532 (Temtaine, in future please provide code, not a URL to some other site, thanks)
56447 has a more compact testcase. *** This bug has been marked as a duplicate of bug 56447 ***