Boost C++ Libraries: Ticket #2929: boost::function cause runtime stack overflow https://svn.boost.org/trac10/ticket/2929 <p> the bug described below is presented in all the boost versions starting from 1.36 and to development trunk </p> <pre class="wiki">#include &lt;boost/function.hpp&gt; void main() { boost::function&lt;void () &gt; f( &amp;main ); boost::function&lt;void () &gt; g; g.assign ( f, std::allocator&lt;int&gt;() ); } </pre><p> this code sample being compiled under MSVC 8.0 SP1 give the following warning </p> <p> warning C4717: 'boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;' : recursive on all control paths, function will cause runtime stack overflow </p> <p> if we run the sample, it does cause stack overflow with the following call stack: </p> <blockquote> <p> ... </p> </blockquote> <blockquote> <p> test_boost.exe!boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;(const boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt; &amp; <span class="underline">that={...}) + 0x39 bytes C++ </span></p> </blockquote> <blockquote> <p> test_boost.exe!boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;(const boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt; &amp; <span class="underline">that={...}) + 0x39 bytes C++ </span></p> </blockquote> <blockquote> <p> test_boost.exe!std::_Construct&lt;boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;,boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt; &gt;(boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt; * _Ptr=0x00185008, const boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt; &amp; _Val={...}) Line 53 + 0x33 bytes C++ </p> </blockquote> <blockquote> <p> test_boost.exe!std::allocator&lt;boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt; &gt;::construct(boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt; * _Ptr=0x00185008, const boost::detail::function::functor_wrapper&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt; &amp; _Val={...}) Line 156 + 0xd bytes C++ </p> </blockquote> <blockquote> <p> test_boost.exe!boost::detail::function::basic_vtable0&lt;void&gt;::assign_functor_a&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;(boost::function&lt;void <span class="underline">cdecl(void)&gt; f={...}, boost::detail::function::function_buffer &amp; functor={...}, std::allocator&lt;int&gt; a={...}, boost::mpl::bool_&lt;0&gt; </span>formal={...}) Line 591 + 0x60 bytes C++ </p> </blockquote> <blockquote> <p> test_boost.exe!boost::detail::function::basic_vtable0&lt;void&gt;::assign_to_a&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;(boost::function&lt;void <span class="underline">cdecl(void)&gt; f={...}, boost::detail::function::function_buffer &amp; functor={...}, std::allocator&lt;int&gt; a={...}, boost::detail::function::function_obj_tag </span>formal={...}) Line 615 C++ </p> </blockquote> <blockquote> <p> test_boost.exe!boost::detail::function::basic_vtable0&lt;void&gt;::assign_to_a&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;(boost::function&lt;void <span class="underline">cdecl(void)&gt; f={...}, boost::detail::function::function_buffer &amp; functor={...}, std::allocator&lt;int&gt; a={...}) Line 497 + 0x47 bytes C++ </span></p> </blockquote> <blockquote> <p> test_boost.exe!boost::function0&lt;void&gt;::assign_to_a&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;(boost::function&lt;void <span class="underline">cdecl(void)&gt; f={...}, std::allocator&lt;int&gt; a={...}) Line 949 + 0x3d bytes C++ </span></p> </blockquote> <blockquote> <p> test_boost.exe!boost::function0&lt;void&gt;::assign&lt;boost::function&lt;void __cdecl(void)&gt;,std::allocator&lt;int&gt; &gt;(boost::function&lt;void <span class="underline">cdecl(void)&gt; f={...}, std::allocator&lt;int&gt; a={...}) Line 802 + 0x34 bytes C++ </span></p> </blockquote> <blockquote> <p> test_boost.exe!main() Line 8 C++ </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2929 Trac 1.4.3 Steven Watanabe Thu, 09 Apr 2009 15:16:17 GMT attachment set https://svn.boost.org/trac10/ticket/2929 https://svn.boost.org/trac10/ticket/2929 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">function_base.hpp.patch</span> </li> </ul> Ticket Steven Watanabe Thu, 09 Apr 2009 15:16:45 GMT <link>https://svn.boost.org/trac10/ticket/2929#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2929#comment:1</guid> <description> <p> MSVC's copy constructor bug strikes again. Patch attached. </p> </description> <category>Ticket</category> </item> <item> <author>Dmitriy Iassenev <iassenev@…></author> <pubDate>Thu, 09 Apr 2009 15:34:22 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2929#comment:2 https://svn.boost.org/trac10/ticket/2929#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2929#comment:1" title="Comment 1">steven_watanabe</a>: </p> <blockquote class="citation"> <p> MSVC's copy constructor bug strikes again. Patch attached. </p> </blockquote> <p> it works! thank you for fast reply :) </p> Ticket Steven Watanabe Thu, 09 Apr 2009 15:52:24 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/2929#comment:3 https://svn.boost.org/trac10/ticket/2929#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> Whoa. This patch still needs to go into the trunk. </p> Ticket Daniel James Fri, 03 Jul 2009 22:22:04 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2929#comment:4 https://svn.boost.org/trac10/ticket/2929#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/54619" title="Work around Visual C++ copy constructor bug. Fixes #2929. Based on ...">[54619]</a>) Work around Visual C++ copy constructor bug. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2929" title="#2929: Bugs: boost::function cause runtime stack overflow (closed: fixed)">#2929</a>. </p> <p> Based on the patch by Steven Watanabe. </p> Ticket Daniel James Wed, 08 Jul 2009 23:23:54 GMT <link>https://svn.boost.org/trac10/ticket/2929#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2929#comment:5</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/54824" title="Merge various function changes from trunk. Merged revisions ...">[54824]</a>) Merge various function changes from trunk. </p> <p> Merged revisions 49571,50064,51743,51745,53722,54616-54619 via svnmerge from <a class="ext-link" href="https://svn.boost.org/svn/boost/trunk"><span class="icon">​</span>https://svn.boost.org/svn/boost/trunk</a> </p> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/49571" title="Both Sun and Pgi on Linux correctly put typeinfo into the std ...">r49571</a> | noel_belcourt | 2008-11-03 18:37:49 +0000 (Mon, 03 Nov 2008) | 9 lines </p> </blockquote> <p> </p> <blockquote> <p> Both Sun and Pgi on Linux correctly put typeinfo into the std namespace, but function_base keys off the BOOST_NO_EXCEPTION_STD_NAMESPACE macro instead of the BOOST_NO_STD_TYPEINFO macro. The attached patch changes function_base to use the typeinfo macro. Because eVC 4.2 doesn't put typeinfo into the std namespace, I need to define BOOST_NO_STD_TYPEINFO only for this eVC version. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/50064" title="Fix -Wundef warning and suspect usage of BOOST_STRICT_CONFIG.">r50064</a> | johnmaddock | 2008-12-02 10:10:46 +0000 (Tue, 02 Dec 2008) | 1 line </p> </blockquote> <p> </p> <blockquote> <p> Fix -Wundef warning and suspect usage of BOOST_STRICT_CONFIG. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/51743" title="Implement an optimization that David Abrahams and myself came up with, ...">r51743</a> | dgregor | 2009-03-13 05:23:53 +0000 (Fri, 13 Mar 2009) | 11 lines </p> </blockquote> <p> </p> <blockquote> <p> Implement an optimization that David Abrahams and myself came up with, where Boost.Function uses a bit in the vtable pointer to indicate when the target function object has a trivial copy constructor, trivial destructor, and fits within the small object buffer. In this case, we just copy the bits of the function object rather than performing an indirect call to the manager. </p> </blockquote> <p> </p> <blockquote> <p> This results in a 60% speedup on a micro-benchmark that copies and calls such function objects repeatedly. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/51745" title="Make Boost.Function compile under BOOST_NO_EXCEPTIONS. Fixes #2499 ...">r51745</a> | dgregor | 2009-03-13 05:49:02 +0000 (Fri, 13 Mar 2009) | 7 lines </p> </blockquote> <p> </p> <blockquote> <p> Make Boost.Function compile under BOOST_NO_EXCEPTIONS. </p> </blockquote> <p> </p> <blockquote> <p> Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2499" title="#2499: Bugs: boost/function/function_template.hpp broken for -fno-exceptions. (closed: fixed)">#2499</a> Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2494" title="#2494: Bugs: compile errors in function_template.hpp when BOOST_NO_EXCEPTIONS defined (closed: fixed)">#2494</a> Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2469" title="#2469: Bugs: Build error in function_template.hpp if BOOST_NO_EXCEPTIONS is defined (closed: fixed)">#2469</a> Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2466" title="#2466: Bugs: function_template.hpp uses exceptions even when BOOST_NO_EXCEPTIONS is ... (closed: fixed)">#2466</a> </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/53722" title="Make Boost.Function compile with disabled exceptions. Closes #2900. ...">r53722</a> | vladimir_prus | 2009-06-07 16:44:50 +0100 (Sun, 07 Jun 2009) | 4 lines </p> </blockquote> <p> </p> <blockquote> <p> Make Boost.Function compile with disabled exceptions. </p> </blockquote> <p> </p> <blockquote> <p> Closes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2900" title="#2900: Bugs: Function Library does not compile with no excpetions (closed: fixed)">#2900</a>. Patch from Gabi Davar. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/54616" title="When copying boost::ref, copy even when the referenced function is ...">r54616</a> | danieljames | 2009-07-03 23:20:26 +0100 (Fri, 03 Jul 2009) | 3 lines </p> </blockquote> <p> </p> <blockquote> <p> When copying boost::ref, copy even when the referenced function is empty. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2642" title="#2642: Bugs: bug constructing from a reference to another boost::function (closed: fixed)">#2642</a> </p> </blockquote> <p> </p> <blockquote> <p> Patch by Steven Watanabe </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/54617" title="Add 'and later versions' to support info for GCC and Visual C++. Fixes ...">r54617</a> | danieljames | 2009-07-03 23:20:52 +0100 (Fri, 03 Jul 2009) | 6 lines </p> </blockquote> <p> </p> <blockquote> <p> Add 'and later versions' to support info for GCC and Visual C++. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2847" title="#2847: Bugs: Additional compatible compilers for preferred syntax (closed: fixed)">#2847</a>. </p> </blockquote> <p> </p> <blockquote> <p> I didn't explicitly specify the versions since no one's updating this list and it's highly unlikely that a future version will break this. The same could probably be done for the other compilers but I don't know them very well so I'm leaving them alone. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/54618" title="Fix Boost.Function unit tests for C++0x. Fixes #3012 Based on a patch ...">r54618</a> | danieljames | 2009-07-03 23:21:40 +0100 (Fri, 03 Jul 2009) | 4 lines </p> </blockquote> <p> </p> <blockquote> <p> Fix Boost.Function unit tests for C++0x. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3012" title="#3012: Bugs: [function] Test failures with GCC 4.3/4.4 in C++0x mode (closed: fixed)">#3012</a> </p> </blockquote> <p> </p> <blockquote> <p> Based on a patch from Richard Webb. Changed a bit so that it also works for the Visual C++ 10 beta. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/54619" title="Work around Visual C++ copy constructor bug. Fixes #2929. Based on ...">r54619</a> | danieljames | 2009-07-03 23:22:03 +0100 (Fri, 03 Jul 2009) | 3 lines </p> </blockquote> <p> </p> <blockquote> <p> Work around Visual C++ copy constructor bug. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2929" title="#2929: Bugs: boost::function cause runtime stack overflow (closed: fixed)">#2929</a>. </p> </blockquote> <p> </p> <blockquote> <p> Based on the patch by Steven Watanabe. </p> </blockquote> <p> ........ </p> </description> <category>Ticket</category> </item> </channel> </rss>