i am new to c++ lambda, and trying to use it. Please excuse me if my bug reports are invalid.
here is something i wished would work, but doesn't. auto sum = [&term,&next,&sum](int a, int b)mutable ->int { if(a>b) return 0; else return term(a) + sum(next(a),b); }; It gives compilation error: vi...@linux-718q:~/Study/09C++/c++0x/lambda> g++ -g -std=c++0x sum.cpp sum.cpp: In lambda function: sum.cpp:13:36: error: ((<lambda(int, int)>*)this)-><lambda(int, int)>::sum cannot be used as a function Then i changed the recursive lambda as follows: std::function<int(int,int)> sum = [&term,&next,&sum](int a, int b)->int { if(a>b) return 0; else return term(a) + sum(next(a),b); }; this seems to compile but gives a core dump. the gdb report is: vi...@linux-718q:~/Study/09C++/c++0x/lambda> gdb a.out GNU gdb (GDB) SUSE (6.8.91.20090930-2.4) Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i586-suse-linux". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/vimal/Study/09C++/c++0x/lambda/a.out...done. (gdb) run Starting program: /home/vimal/Study/09C++/c++0x/lambda/a.out Missing separate debuginfo for /lib/ld-linux.so.2 Try: zypper install -C "debuginfo(build-id)=d7706cbaa0ca09319cb645eac789cb8399078797" Missing separate debuginfo for /lib/libm.so.6 Try: zypper install -C "debuginfo(build-id)=a488c775caa0433cb23f9764d683150f40872ef1" Missing separate debuginfo for /lib/libc.so.6 Try: zypper install -C "debuginfo(build-id)=ee302691046515fe3766ae3b7d47afd3e3a8d063" Program received signal SIGSEGV, Segmentation fault. 0x0804889b in _Base_manager<<lambda(int, int)> >::_M_get_pointer(const std::_Any_data &) (__source=...) at /usr/local/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/functional:1569 1569 /* have stored a pointer */ : __source._M_access<_Functor*>(); (gdb) -- Summary: core dump in recursive lambda function Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: vimal78 at gmail dot com GCC build triplet: version 4.5.0 20091231 (experimental) GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42741