Boost C++ Libraries: Ticket #5098: [result_of] decltype-based result_of cannot handle rvalue-reference correctly https://svn.boost.org/trac10/ticket/5098 <p> The implementation of decltype-based boost::result_of is essentially the same as </p> <pre class="wiki">// This code is taken from N1454 (author: Douglas Gregor) template &lt;typename F, typename T1, typename T2, ..., typename TN&gt; class result_of&lt;F(T1, T2, ..., TN)&gt; { static F f; static T1 t1; static T2 t2; . . . static TN tN; public: // Note: even if Ti is rvalue reference, ti is treated as lvalue. typedef decltype(f(t1, t2, ..., tN)) type; }; </pre><p> So, the implementation cannot handle rvalue-reference correctly (it becomes lvalue). </p> <p> For example, in the following code </p> <pre class="wiki">struct func { unsigned char operator()(int&amp;&amp; ) { return 0; } signed char operator()(int&amp; ) { return 0; } char operator()(int const&amp;) { return 0; } }; </pre><p> <code>boost::result_of&lt;func(int)&gt;::type</code> is <code>signed char</code> (which should be <code>unsigned char</code>). </p> <p> I will attach a patch for fixing this issue. The patch uses <code>declval</code> rather than static members. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5098 Trac 1.4.3 mimomorin@… Thu, 20 Jan 2011 09:59:10 GMT attachment set https://svn.boost.org/trac10/ticket/5098 https://svn.boost.org/trac10/ticket/5098 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">result_of.patch</span> </li> </ul> <p> A patch against trunk (boost/utility/result_of.hpp, boost/utility/detail/result_of_iterate.hpp) </p> Ticket mimomorin@… Thu, 20 Jan 2011 10:24:42 GMT attachment set https://svn.boost.org/trac10/ticket/5098 https://svn.boost.org/trac10/ticket/5098 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">result_of_test.patch</span> </li> </ul> <p> A patch against trunk (libs/utility/test/result_of_test.cpp) </p> Ticket mimomorin@… Thu, 20 Jan 2011 10:43:30 GMT <link>https://svn.boost.org/trac10/ticket/5098#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5098#comment:1</guid> <description> <p> Replying to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5098" title="#5098: Patches: [result_of] decltype-based result_of cannot handle rvalue-reference ... (closed: fixed)">mimomorin@…</a>: </p> <blockquote class="citation"> <p> <code>boost::result_of&lt;func(int)&gt;::type</code> is <code>signed char</code> (which should be <code>unsigned char</code>). </p> </blockquote> <p> This is a typo (though this sentence is still true). </p> <p> What I meant is: </p> <p> <code>boost::result_of&lt;func(int&amp;&amp;)&gt;::type</code> is <code>signed char</code> (which should be <code>unsigned char</code>). </p> </description> <category>Ticket</category> </item> <item> <author>mimomorin@…</author> <pubDate>Thu, 20 Jan 2011 13:12:37 GMT</pubDate> <title>owner, type changed https://svn.boost.org/trac10/ticket/5098#comment:2 https://svn.boost.org/trac10/ticket/5098#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">No-Maintainer</span> to <span class="trac-author">Daryle Walker</span> </li> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Patches</span> </li> </ul> Ticket mimomorin@… Sat, 22 Jan 2011 02:06:18 GMT owner changed https://svn.boost.org/trac10/ticket/5098#comment:3 https://svn.boost.org/trac10/ticket/5098#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Daryle Walker</span> to <span class="trac-author">Daniel Walker</span> </li> </ul> Ticket Daniel Walker Sat, 22 Jan 2011 22:18:51 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5098#comment:4 https://svn.boost.org/trac10/ticket/5098#comment:4 <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/68373" title="use declval to fix #5098">[68373]</a>) use declval to fix <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5098" title="#5098: Patches: [result_of] decltype-based result_of cannot handle rvalue-reference ... (closed: fixed)">#5098</a> </p> Ticket Daniel Walker Sat, 22 Jan 2011 22:25:28 GMT <link>https://svn.boost.org/trac10/ticket/5098#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5098#comment:5</guid> <description> <p> I applied the patches with one modification: instead of defining its own declval, it uses boost::declval. Thanks for input and patches! </p> </description> <category>Ticket</category> </item> </channel> </rss>