Boost C++ Libraries: Ticket #4325: boost::function target method fails after copy constructing a function containing a ref https://svn.boost.org/trac10/ticket/4325 <p> Attached is a simple reproduction case that creates a boost::function containing a boost::ref, copy constructs a second one from the first, and then attempts to get the target object from the second function object. Using g++ 4.2.1 on Mac OS X 10.6.3, this prints out a valid pointer if compiled -O0, but prints "0" (NULL) if compiled -O2. I have done some debugging and believe the problem lies in the function boost::detail::function::reference_manager::manage (line 201 of function_base.hpp in Boost 1.43.0). Each tag case in this function copies only the obj_ptr piece of the obj_ref field. In the case of the boost::function copy constructor, which eventually calls the manage function with clone_functor_tag, this leaves the is_const_qualified and is_volatile_qualified fields of the constructed object uninitialized, leading to sporadic results. Also, I was not able to reproduce this on Linux, and I believe that is because on Linux, the has_trivial_copy_and_destroy method reports true, which causes the manage method to be bypassed, but on Mac OS X, it reports false. I was able to get my test case to pass by changing </p> <blockquote> <p> out_buffer.obj_ref.obj_ptr = in_buffer.obj_ref.obj_ptr; </p> </blockquote> <p> in the clone_functor_tag case to </p> <blockquote> <p> out_buffer.obj_ref = in_buffer.obj_ref; </p> </blockquote> <p> but I suspect similar changes need to be made for the other tags as well. </p> <p> Also note that this affects operator== and operator!=, which are implemented in terms of target. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4325 Trac 1.4.3 Scott French <scott@…> Wed, 09 Jun 2010 13:35:29 GMT attachment set https://svn.boost.org/trac10/ticket/4325 https://svn.boost.org/trac10/ticket/4325 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test_function.cpp</span> </li> </ul> <p> Reproduction example </p> Ticket Steven Watanabe Wed, 09 Jun 2010 15:40:50 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4325#comment:1 https://svn.boost.org/trac10/ticket/4325#comment:1 <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> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/62665" title="Make sure that the cv flags are copied when we copy a reference to a ...">[62665]</a>) Make sure that the cv flags are copied when we copy a reference to a function object. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4325" title="#4325: Bugs: boost::function target method fails after copy constructing a function ... (closed: fixed)">#4325</a> </p> Ticket Daniel James Mon, 21 Mar 2011 21:32:44 GMT <link>https://svn.boost.org/trac10/ticket/4325#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4325#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/70361" title="Function: Merge from trunk. - Remove extra definition of operator(), ...">[70361]</a>) Function: Merge from trunk. </p> <ul><li>Remove extra definition of operator(), since it's inline anyway. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4765" title="#4765: Bugs: function_template.hpp incorrect placement of inline keyword (closed: fixed)">#4765</a>. </li><li>Make sure that the cv flags are copied when we copy a reference to a function object. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4325" title="#4325: Bugs: boost::function target method fails after copy constructing a function ... (closed: fixed)">#4325</a> </li><li>Fully qualified function calls to avoid ambiguity with new additions to standard. Thanks to Conrad Poelman. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4073" title="#4073: Bugs: &lt;boost/function/function_template.hpp&gt; compile errors with Visual ... (closed: fixed)">#4073</a> </li><li>Remove iterator workaround for newer versions of Visual Age C++. Thanks to 'ccambly'. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3912" title="#3912: Bugs: Boost.Function function30 with vacpp on AIX (closed: fixed)">#3912</a> </li><li>Fix unused variable warning for Visual C++. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3618" title="#3618: Patches: MSVC Warning suppression fix (closed: fixed)">#3618</a> </li><li>Testing flag for Visual C++. </li><li>Removed all but one old-style cast, prevents GCC warnings, but breaks GCC 2.95.3. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3410" title="#3410: Bugs: Warnings in Boost::function when compiled with &#34;-Wold-style-cast&#34; (closed: fixed)">#3410</a> </li><li>Fixed tab and newline issues from inspection report. </li></ul> </description> <category>Ticket</category> </item> </channel> </rss>