Boost C++ Libraries: Ticket #10340: No boost::promise<T>::set_value(const T&) overload present in C++03 mode https://svn.boost.org/trac10/ticket/10340 <p> When compiling in C++03 mode I am unable to use anything but a primitive type in a promise, and therefore also the dependent types in Boost.Thread </p> <p> Minimal testcase: </p> <pre class="wiki"> #include &lt;boost/thread/future.hpp&gt; struct foo { foo(int i_): i(i_) {} int i; }; int main() { // Clearly a const future ref isn't much use, but I needed to // prove the problem wasn't me trying to copy a unique_future const boost::unique_future&lt;foo&gt;&amp; fut = boost::make_ready_future( foo(42) ); } </pre><p> Output from g++ 4.8.2 with Boost 1.55 and -DBOOST_THREAD_USES_MOVE: </p> <blockquote> <p> In file included from ../../deps/boost/include/boost/tuple/tuple.hpp:33:0, </p> <blockquote> <p> from ../../deps/boost/include/boost/thread/detail/async_func.hpp:37, from ../../deps/boost/include/boost/thread/future.hpp:22, from t.cpp:2: </p> </blockquote> <p> ../../deps/boost/include/boost/tuple/detail/tuple_basic.hpp: In function ‘typename boost::tuples::access_traits&lt;typename boost::tuples::element&lt;N, boost::tuples::cons&lt;HT, TT&gt; &gt;::type&gt;::const_type boost::tuples::get(const boost::tuples::cons&lt;HT, TT&gt;&amp;)’: ../../deps/boost/include/boost/tuple/detail/tuple_basic.hpp:228:45: warning: typedef ‘cons_element’ locally defined but not used [-Wunused-local-typedefs] </p> <blockquote> <p> typedef BOOST_DEDUCED_TYPENAME impl::type cons_element; </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> <p> In file included from ../../deps/boost/include/boost/bind/bind.hpp:29:0, </p> <blockquote> <blockquote> <p> from ../../deps/boost/include/boost/bind.hpp:22, from ../../deps/boost/include/boost/thread/future.hpp:41, from t.cpp:2: </p> </blockquote> </blockquote> <p> ../../deps/boost/include/boost/bind/arg.hpp: In constructor ‘boost::arg&lt;I&gt;::arg(const T&amp;)’: ../../deps/boost/include/boost/bind/arg.hpp:37:22: warning: typedef ‘T_must_be_placeholder’ locally defined but not used [-Wunused-local-typedefs] </p> <blockquote> <blockquote> <p> typedef char T_must_be_placeholder[ I == is_placeholder&lt;T&gt;::value? 1: -1 ]; </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> </blockquote> <p> t.cpp: In function ‘int main()’: t.cpp:12:78: error: expected primary-expression before ‘f’ </p> <blockquote> <blockquote> <p> const boost::unique_future&lt;foo&gt;&amp; fut = boost::make_ready_future( foo f(42) ); </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> </blockquote> <p> t.cpp:12:42: warning: unused variable ‘fut’ [-Wunused-variable] </p> <blockquote> <blockquote> <p> const boost::unique_future&lt;foo&gt;&amp; fut = boost::make_ready_future( foo f(42) ); </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> </blockquote> <p> In file included from ../../deps/boost/include/boost/system/system_error.hpp:14:0, </p> <blockquote> <blockquote> <blockquote> <p> from ../../deps/boost/include/boost/thread/exceptions.hpp:22, from ../../deps/boost/include/boost/thread/pthread/mutex.hpp:12, from ../../deps/boost/include/boost/thread/mutex.hpp:16, from ../../deps/boost/include/boost/thread/future.hpp:24, from t.cpp:2: </p> </blockquote> </blockquote> </blockquote> <p> ../../deps/boost/include/boost/system/error_code.hpp: At global scope: ../../deps/boost/include/boost/system/error_code.hpp:222:36: warning: ‘boost::system::posix_category’ defined but not used [-Wunused-variable] </p> <blockquote> <blockquote> <p> static const error_category &amp; posix_category = generic_category(); </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> </blockquote> <p> ../../deps/boost/include/boost/system/error_code.hpp:223:36: warning: ‘boost::system::errno_ecat’ defined but not used [-Wunused-variable] </p> <blockquote> <blockquote> <p> static const error_category &amp; errno_ecat = generic_category(); </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> </blockquote> <p> ../../deps/boost/include/boost/system/error_code.hpp:224:36: warning: ‘boost::system::native_ecat’ defined but not used [-Wunused-variable] </p> <blockquote> <blockquote> <p> static const error_category &amp; native_ecat = system_category(); </p> </blockquote> </blockquote> </blockquote> <p> I have replicated this with Clang 3.4, also with Boost 1.54 on both compilers, and without -DBOOST_THREAD_USES_MOVE too. From the boost-users mailing list it looks like it has been replicated with 1.56 too. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10340 Trac 1.4.3 anonymous Mon, 11 Aug 2014 11:38:50 GMT <link>https://svn.boost.org/trac10/ticket/10340#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10340#comment:1</guid> <description> <p> The error you pasted is due to a syntax error and doesn't match the code you pasted: </p> <pre class="wiki">t.cpp: In function ‘int main()’: t.cpp:12:78: error: expected primary-expression before ‘f’ const boost::unique_future&lt;foo&gt;&amp; fut = boost::make_ready_future( foo f(42) ); </pre><p> (Also the output would be a lot more useful with <code>-Wno-unused-local-typedefs</code>) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 11 Aug 2014 11:43:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10340#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10340#comment:2</guid> <description> <p> Simpler test case: </p> <pre class="wiki">#include &lt;boost/thread/future.hpp&gt; struct foo { foo(int i_) { } }; int main() { boost::promise&lt;foo&gt; p; const foo f(42); p.set_value(f); } </pre><p> This fails with -DBOOST_THREAD_USES_MOVE but compiles OK without. </p> </description> <category>Ticket</category> </item> <item> <author>rob.desbois@…</author> <pubDate>Wed, 13 Aug 2014 08:53:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10340#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10340#comment:3</guid> <description> <p> Agh, apologies for the brainfail there. Problem hopefully clear from the bug title, but for completeness here is the compile error with 1.55, g++ 4.8.2, and -DBOOST_THREAD_USES_MOVE: </p> <pre class="wiki">In file included from t.cpp:1:0: ../deps/boost/include/boost/thread/future.hpp: In instantiation of ‘boost::unique_future&lt;typename boost::decay&lt;T&gt;::type&gt; boost::make_ready_future(const T&amp;) [with T = foo; typename boost::decay&lt;T&gt;::type = foo]’: t.cpp:14:35: required from here ../deps/boost/include/boost/thread/future.hpp:3634:5: error: no matching function for call to ‘boost::promise&lt;foo&gt;::set_value(const foo&amp;)’ p.set_value(boost::forward&lt;future_value_type&gt;(value)); ^ ../deps/boost/include/boost/thread/future.hpp:3634:5: note: candidates are: In file included from t.cpp:1:0: ../deps/boost/include/boost/thread/future.hpp:2052:14: note: void boost::promise&lt;R&gt;::set_value(typename boost::detail::future_traits&lt;T&gt;::source_reference_type) [with R = foo; typename boost::detail::future_traits&lt;T&gt;::source_reference_type = foo&amp;] void set_value(typename detail::future_traits&lt;R&gt;::source_reference_type r) ^ ../deps/boost/include/boost/thread/future.hpp:2052:14: note: no known conversion for argument 1 from ‘const foo’ to ‘boost::detail::future_traits&lt;foo&gt;::source_reference_type {aka foo&amp;}’ ../deps/boost/include/boost/thread/future.hpp:2064:14: note: void boost::promise&lt;R&gt;::set_value(typename boost::detail::future_traits&lt;T&gt;::rvalue_source_type) [with R = foo; typename boost::detail::future_traits&lt;T&gt;::rvalue_source_type = boost::rv&lt;foo&gt;&amp;] void set_value(typename detail::future_traits&lt;R&gt;::rvalue_source_type r) ^ ../deps/boost/include/boost/thread/future.hpp:2064:14: note: no known conversion for argument 1 from ‘const foo’ to ‘boost::detail::future_traits&lt;foo&gt;::rvalue_source_type {aka boost::rv&lt;foo&gt;&amp;}’ </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 21 Aug 2014 08:03:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10340#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10340#comment:4</guid> <description> <p> IIUC you need to make <code>foo</code> movable in C++98 compilers. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 24 Aug 2014 23:57:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10340#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10340#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10340#comment:4" title="Comment 4">viboes</a>: </p> <blockquote class="citation"> <p> IIUC you need to make <code>foo</code> movable in C++98 compilers. </p> </blockquote> <p> Forget this comment, please :( </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 30 Aug 2014 10:05:58 GMT</pubDate> <title>description changed https://svn.boost.org/trac10/ticket/10340#comment:6 https://svn.boost.org/trac10/ticket/10340#comment:6 <ul> <li><strong>description</strong> modified (<a href="/trac10/ticket/10340?action=diff&amp;version=6">diff</a>) </li> </ul> Ticket viboes Sat, 30 Aug 2014 10:06:49 GMT description changed https://svn.boost.org/trac10/ticket/10340#comment:7 https://svn.boost.org/trac10/ticket/10340#comment:7 <ul> <li><strong>description</strong> modified (<a href="/trac10/ticket/10340?action=diff&amp;version=7">diff</a>) </li> </ul> Ticket viboes Sat, 30 Aug 2014 11:46:20 GMT <link>https://svn.boost.org/trac10/ticket/10340#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10340#comment:8</guid> <description> <p> Please, could you tell me if the following patch works for you </p> <pre class="wiki">git diff ../include/boost/thread/future.hpp diff --git a/include/boost/thread/future.hpp b/include/boost/thread/future.hpp index 184d305..c7e81d5 100644 --- a/include/boost/thread/future.hpp +++ b/include/boost/thread/future.hpp @@ -553,7 +553,7 @@ namespace boost //typedef typename conditional&lt;boost::is_fundamental&lt;T&gt;::value,T,BOOST_THREAD_RV_REF(T)&gt;::type move_dest_type; typedef T move_dest_type; #elif defined BOOST_THREAD_USES_MOVE - typedef typename conditional&lt;boost::is_fundamental&lt;T&gt;::value,T,T&amp;&gt;::type source_reference_type; + typedef typename conditional&lt;boost::is_fundamental&lt;T&gt;::value,T,T const&amp;&gt;::type source_reference_type; //typedef typename conditional&lt;boost::is_fundamental&lt;T&gt;::value,T,BOOST_THREAD_RV_REF(T)&gt;::type rvalue_source_type; //typedef typename conditional&lt;boost::enable_move_utility_emulation&lt;T&gt;::value,BOOST_THREAD_RV_REF(T),T&gt;::type move_dest_type; typedef BOOST_THREAD_RV_REF(T) rvalue_source_type; </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 30 Aug 2014 16:00:32 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/10340#comment:9 https://svn.boost.org/trac10/ticket/10340#comment:9 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.57.0</span> </li> </ul> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/0543b522cb6c2af197a82dea48805ea19be6f4f7"><span class="icon">​</span>https://github.com/boostorg/thread/commit/0543b522cb6c2af197a82dea48805ea19be6f4f7</a> </p> Ticket rob.desbois@… Thu, 04 Sep 2014 12:34:02 GMT <link>https://svn.boost.org/trac10/ticket/10340#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10340#comment:10</guid> <description> <p> It does indeed; thanks viboes. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 05 Sep 2014 06:08:23 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/10340#comment:11 https://svn.boost.org/trac10/ticket/10340#comment:11 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Tue, 16 Sep 2014 06:14:57 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10340#comment:12 https://svn.boost.org/trac10/ticket/10340#comment:12 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket