[Boost-bugs] [Boost C++ Libraries] #8674: Futures as local named objects can't be returned with implicit move.

Subject: [Boost-bugs] [Boost C++ Libraries] #8674: Futures as local named objects can't be returned with implicit move.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-06-08 15:37:08


#8674: Futures as local named objects can't be returned with implicit move.
------------------------------+----------------------
 Reporter: mjklaim@… | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: thread
  Version: Boost 1.53.0 | Severity: Problem
 Keywords: |
------------------------------+----------------------
 I could test only with VS 2012 Update 2 so this might be related to a
 compiler bug, but I can't test the boost code with other
 compilers/platforms right now.

 I have this simple test:


 {{{
 #include <iostream>

 #define USE_STD 0
 #define USE_BOOST 1

 #define USED_THREAD_API USE_BOOST

 #if USED_THREAD_API == USE_BOOST

 # define BOOST_THREAD_VERSION 4
 # include <boost/thread/future.hpp>

         using boost::future;
         using boost::async;

 #endif
 #if USED_THREAD_API == USE_STD
 # include <future>
         using std::future;
         using std::async;
 #endif



 future<void> do_something()
 {
         auto result = async( []{ std::cout<< "A\n"; } );
         std::cout << "B\n";
         return result; // error here
 }

 int main()
 {
         do_something().wait();
         std::cout << "Hello, World!" << std::endl;

 }

 }}}

 Both default Debug and Release modes fail to compile on VS2012 U2:

 {{{

 1>------ Build started: Project: Test_MoveReturnFuture, Configuration:
 Debug Win32 ------
 1> main.cpp
 1>e:\projects\tests\test_movereturnfuture\test_movereturnfuture\main.cpp(29):
 error C2248: 'boost::future<R>::future' : cannot access private member
 declared in class 'boost::future<R>'
 1> with
 1> [
 1> R=void
 1> ]
 1> e:\projects\sdk\boost\boost\include\boost-
 1_53\boost\thread\future.hpp(1406) : see declaration of
 'boost::future<R>::future'
 1> with
 1> [
 1> R=void
 1> ]
 ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
 ==========
 }}}

 Changing this line:

 {{{
 #define USED_THREAD_API USE_BOOST
 }}}

 To this:

 {{{
 #define USED_THREAD_API USE_STD
 }}}

 Makes it compile and execute fine.

 I see that there are move constructors in the definition of future so I
 don't know at all what's the difference between the two implementations.

 Another way to avoid the problem is to explicitly move the future:


 {{{
 future<void> do_something()
 {
         auto result = async( []{ std::cout<< "A\n"; } );
         std::cout << "B\n";
         return std::move(result);
 }
 }}}


 Which is what I have been doing in my code because I was initially
 thinking it was a compiler bug, but this Q/A made me reconsider:
 http://stackoverflow.com/questions/4986673/c11-rvalues-and-move-semantics-
 confusion

 I cannot test Boost 1.54 at the moment.

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