https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67952
Bug ID: 67952 Summary: Compilation error with boost::signals2 and generic lambda: cannot call member function without object Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jens.auer at cgi dot com Target Milestone: --- Created attachment 36495 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36495&action=edit Preprocessed source code The following code doesn't compile with boost 1.59 and gcc 5.1, but with clang 3.6: #include <boost/signals2.hpp> class A { public: A() { // these two work sig2.connect( [this]() {f();} ); sig.connect( [this](auto x) {this->g(x);} ); // this does not work sig.connect( [this](auto x) {g(x);} ); } private: void f(); void g(int); boost::signals2::signal<void (int)> sig; boost::signals2::signal<void ()> sig2; }; The error message is shadow.cpp: In instantiation of ‘A::A()::<lambda(auto:2)> [with auto:2 = int]’: /lhome1/auerj/opt/include/boost/function/function_template.hpp:153:11: required from ‘static void boost::detail::function::void_function_obj_invoker1<FunctionObj, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = A::A()::<lambda(auto:2)>; R = void; T0 = int]’ /lhome1/auerj/opt/include/boost/function/function_template.hpp:934:38: required from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = A::A()::<lambda(auto:2)>; R = void; T0 = int]’ /lhome1/auerj/opt/include/boost/function/function_template.hpp:722:7: required from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), int>::type) [with Functor = A::A()::<lambda(auto:2)>; R = void; T0 = int; typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), int>::type = int]’ /lhome1/auerj/opt/include/boost/function/function_template.hpp:1071:16: required from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), int>::type) [with Functor = A::A()::<lambda(auto:2)>; R = void; T0 = int; typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), int>::type = int]’ /lhome1/auerj/opt/include/boost/function/function_template.hpp:1126:5: required from ‘typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), boost::function<R(T0)>&>::type boost::function<R(T0)>::operator=(Functor) [with Functor = A::A()::<lambda(auto:2)>; R = void; T0 = int; typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral<Functor>::value)>::value), boost::function<R(T0)>&>::type = boost::function<void(int)>&]’ /lhome1/auerj/opt/include/boost/signals2/detail/slot_template.hpp:160:24: required from ‘void boost::signals2::slot<R(Args ...), SlotFunction>::init_slot_function(const F&) [with F = A::A()::<lambda(auto:2)>; SlotFunction = boost::function<void(int)>; R = void; Args = {int}]’ /lhome1/auerj/opt/include/boost/signals2/detail/slot_template.hpp:85:27: required from ‘boost::signals2::slot<R(Args ...), SlotFunction>::slot(const F&) [with F = A::A()::<lambda(auto:2)>; SlotFunction = boost::function<void(int)>; R = void; Args = {int}]’ shadow.cpp:13:45: required from here shadow.cpp:13:38: error: cannot call member function ‘void A::g(int)’ without object sig.connect( [this](auto x) {g(x);} ); I think it is a compiler bug because adding the implicit this-> solves the problem (see second connect). My gcc version: g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/lhome1/auerj/opt/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-5.1.0/configure --prefix=/lhome1/auerj/opt --enable-languages=c,c++ Thread model: posix gcc version 5.1.0 (GCC) I have attached the preprocessed output so it should be easy to reproduce the issue. It is probably a duplicate of 61636, but I such that it can be tracked as such. I guess boost::signals2 is a popular library, so it may be worth to have it in the database explicitly.