Boost logo

Boost :

Subject: [boost] [function][bind] Crash with g++ 4.5.0 -O[23]
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2011-08-08 15:44:56


I recently wrote some code that only crashes with g++ 4.5.0 -O[23] and am not sure whether it is a g++, boost::bind, or boost::function bug. I have prepared a minimum test case that crashes every time:

0 test 0x00000001000016ba Private::method_name(std::string const&) + 26
1 test 0x0000000100001348 boost::detail::function::function_obj_invoker1<boost::_bi::bind_t<void_t, boost::_mfi::mf1<void_t, Private, std::string const&>, boost::_bi::list2<boost::_bi::value<Private*>, boost::arg<1> > >, void_t, std::string const&>::invoke(boost::detail::function::function_buffer&, std::string const&) + 24
2 test 0x00000001000027bb boost::detail::function::void_function_obj_invoker2<functor<std::string, boost::function<void_t ()(std::string const&)> >, void, std::string const&, std::string&>::invoke(boost::detail::function::function_buffer&, std::string const&, std::string&) + 59
3 test 0x0000000100003893 Private::test() + 2723
4 test 0x00000001000012d8 main + 56
5 test 0x0000000100001250 start + 52

Mac OS X 10.6 Snow Leopard
g++-4.5.0 -O3 or -02 crashes
g++-4.5.0 -O1 works.
g++-4.2 -O3 works.
g++-4.0 -O3 works
llvm-g++-4.2 -O3 works

The odd thing is that if I replace boost::bind() with my own custom functor then it does not crash.
If I include both working and non-working functors (uncomment code) then they both work.

Because older versions of g++ work (pre C++0x support) it could be a bug in how boost::function or boost::bind use rvalue references. Because replacing boost::bind() with my own custom functor also fixes it, I suspect that the problem, if not g++, lies in boost::bind.

If I remove boost::function from the equation by creating functor<Seq,Functor> with Functor = TYPEOF( boost::bind( ... ) ) via the use of a helper method, then it also does not crash. Thus some combination of creating a boost::function<...> from a boost::bind() functor on g++4.5 causes the crash.




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk