[Boost-bugs] [Boost C++ Libraries] #4325: boost::function target method fails after copy constructing a function containing a ref

Subject: [Boost-bugs] [Boost C++ Libraries] #4325: boost::function target method fails after copy constructing a function containing a ref
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-06-09 13:34:29


#4325: boost::function target method fails after copy constructing a function
containing a ref
------------------------------------------------+---------------------------
 Reporter: Scott French <scott@…> | Owner: dgregor
     Type: Bugs | Status: new
Milestone: Boost 1.43.0 | Component: function
  Version: Boost Development Trunk | Severity: Regression
 Keywords: function ref copy constructor |
------------------------------------------------+---------------------------
 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

             out_buffer.obj_ref.obj_ptr = in_buffer.obj_ref.obj_ptr;

 in the clone_functor_tag case to

             out_buffer.obj_ref = in_buffer.obj_ref;

 but I suspect similar changes need to be made for the other tags as well.

 Also note that this affects operator== and operator!=, which are
 implemented in terms of target.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4325>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:03 UTC