[Boost-bugs] [Boost C++ Libraries] #4367: Proposed fix for test_thread_move_return.cpp

Subject: [Boost-bugs] [Boost C++ Libraries] #4367: Proposed fix for test_thread_move_return.cpp
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-06-22 19:16:46


#4367: Proposed fix for test_thread_move_return.cpp
---------------------------------------+------------------------------------
 Reporter: sergey.sprogis@… | Owner:
     Type: Bugs | Status: new
Milestone: Boost 1.44.0 | Component: None
  Version: Boost 1.44.0 | Severity: Problem
 Keywords: test_thread_move_return |
---------------------------------------+------------------------------------
 Bug description:
 ----------------

 The original statement in test_thread_move_return.cpp (Line 16):

   return boost::move(t);

 triggered the following error message in Sun C++ compiler (this compiler
 assumes that Boost has fix #4305 for boost/thread/detail/thread.hpp):

 ============================================
 "test_thread_move_return.cpp", line 16: Error: Cannot use
 boost::detail::thread_move_t<boost::thread> to initialize boost::thread
 without "boost::thread::boost::thread(const boost::thread&)";.
 1 Error(s) detected.
 ============================================

 and the same test built with gcc-4.4.4 also failed in a similar way

 ============================================

 test_thread_move_return.cpp: In function 'boost::thread
 make_thread_move_return(boost::thread::id*)':
 test_thread_move_return.cpp:16: error: no matching function for call to
 'boost::thread::thread(boost::thread)'
 ../../../boost/thread/detail/thread.hpp:202: note: candidates are:
 boost::thread::thread(boost::detail::thread_move_t<boost::thread>)
 ../../../boost/thread/detail/thread.hpp:150: note:
 boost::thread::thread()
 ../../../boost/thread/detail/thread.hpp:108: note:
 boost::thread::thread(boost::thread&)
 ============================================

 Sun compiler reports the failure because for the following reason.

 After finding user-defined copy constructor in
 boost/thread/detail/thread.hpp (line 108) thread(thread&); compiler
 does not provide the default copy constructor with 'const' qualifier like
 thread(const thread&).

 Then later, when compiler processes test's return statement (line 16)

   return boost::move(t);

 a copy constructor is needed to return the temporary thread object by
 value from make_thread_move_return(), but there is no viable copy
 constructor. The existing copy constructor cannot be used because it's
 not allowed to bind an rvalue (the temporary thread object) to a
 non-const reference. (Std 2003 13.3.3.1.4:3 )

 So, the result is an error message mentioned above.

 Meantime, after replacing

 return boost::move(t);

 with

 return boost::thread(boost::move(t));

 compiler does not need copy constructor to create the result object,
 only user-defined conversion constructor thread(thread_move_t) is
 used (Std 2003 8.5/14).

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4367>
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