Boost C++ Libraries: Ticket #7251: is_convertible works incorrectly for rvalue source types https://svn.boost.org/trac10/ticket/7251 <p> As reported by John Bytheway at <a class="ext-link" href="http://lists.boost.org/Archives/boost/2012/08/195575.php"><span class="icon">​</span>boost-devel ML</a>, non-intrinsic version of <code>is_convertible&lt;From, To&gt;</code> works incorrectly when <code>From</code> is rvalues. The current code incorrectly handles <code>From</code> as an lvalue, even if it is an rvalue. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7251 Trac 1.4.3 Michel Morin Sun, 19 Aug 2012 14:40:13 GMT attachment set https://svn.boost.org/trac10/ticket/7251 https://svn.boost.org/trac10/ticket/7251 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">fix_is_convertible_for_rvalues_cxx11.patch</span> </li> </ul> <p> Patch for C++11 </p> Ticket Michel Morin Sun, 19 Aug 2012 14:42:19 GMT <link>https://svn.boost.org/trac10/ticket/7251#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7251#comment:1</guid> <description> <p> Attached a patch for C++11. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sun, 26 Aug 2012 12:14:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7251#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7251#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/80234" title="Move new test cases into the &#34;tricky&#34; section as many compilers can't ...">[80234]</a>) Move new test cases into the "tricky" section as many compilers can't handle them. Revert previous change that used std::is_convertible on GCC as it breaks code prior to gcc-4.7. Fix MSVC intrinsic to handle function types better. Filter out rvalue-refs from is_function. Partially apply patch from <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7251" title="#7251: Patches: is_convertible works incorrectly for rvalue source types (closed: obsolete)">#7251</a> to make is_convertible behave more according to C++11. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7251" title="#7251: Patches: is_convertible works incorrectly for rvalue source types (closed: obsolete)">#7251</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sun, 26 Aug 2012 12:20:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7251#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7251#comment:3</guid> <description> <p> Michel, </p> <p> I've moved the extra test cases you added into the tricky*.cpp files as more than a few compilers fail these cases (once the main test file stops building, then we're no longer testing anything at all on that compiler, so I'd prefer to keep troublesome test cases separate). </p> <p> I've applied the patch, but restricted it's application to GCC to versions 4.7 and later - earlier versions don't build the test suite with the patch applied :-( Versions 4.5.x and 4.6.x fail to build with function types, while version 4.4.x fails with just about everything. </p> <p> It's possible that an extra #if branch for SFINAE-expressions could fix the remaining issues, but equally it might just break more stuff :-( </p> <p> Cheers, John. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Michel Morin</dc:creator> <pubDate>Thu, 30 Aug 2012 16:31:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7251#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7251#comment:4</guid> <description> <p> Hi John, </p> <p> Thanks for looking into the problem. <br /><br /> </p> <blockquote class="citation"> <p> I've applied the patch, but restricted it's application to GCC to versions 4.7 and later - earlier versions don't build the test suite with the patch applied :-<br /> (Versions 4.5.x and 4.6.x fail to build with function types, </p> </blockquote> <p> gcc 4.3-4.6 implements C++0x drafts, and there are some inconsistencies with C++11. For example, </p> <ul><li>gcc 4.3-4.4: rvalue references can be bound to lvalues. </li><li>gcc 4.5-4.6: rvalue references to function type is not an lvalue. So, for a function type <code>Func</code>, <code>Func&amp;</code> cannot be bound to <code>Func&amp;&amp;</code>. Accordingly, <code>is_convertible&lt;Func, Func&amp;&gt;</code> returns different results than C++11 and this causes the test failures. </li></ul><p> <br /> </p> <blockquote class="citation"> <p> while version 4.4.x fails with just about everything.<br /><br /> It's possible that an extra #if branch for SFINAE-expressions could fix the remaining issues, but equally it might just break more stuff :-( </p> </blockquote> <p> Since <code>T</code> is not a dependent type in<code>_m_check</code>, SFINAE is not related. Indeed, the errors on gcc 4.3-4.4 can be reproduced without using templates. (And note that gcc 4.4 supports SFINAE for expressions.) I guess that the reason for the test failures on gcc 4.3-4.4 is a compiler's bug related to rvalue references. </p> <p> <code>#if</code> branch is not needed for <code>BOOST_NO_SFINAE_EXPR</code>, but is needed for <code>__GNUC__ == 4 &amp;&amp; (__GNUC_MINOR__ == 3 || __GNUC_MINOR__ == 4)</code>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Michel Morin</dc:creator> <pubDate>Fri, 31 Aug 2012 01:04:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7251#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7251#comment:5</guid> <description> <p> On gcc 4.5-4.6 in a C++11 mode, <code>Func&amp;&amp;</code> cannot be bound to <code>const Func&amp;</code>. This is because, </p> <ul><li>An rvalue reference to function type is an rvalue, on these compilers. </li><li>Function type cannot be cv-qualified. </li></ul><p> So, on these compilers, <code>any_conversion</code> needs constructors taking rvalue references: </p> <pre class="wiki">struct any_conversion { #ifndef BOOST_NO_RVALUE_REFERENCES template &lt;typename T&gt; any_conversion(T&amp;&amp;); #else template &lt;typename T&gt; any_conversion(const volatile T&amp;); template &lt;typename T&gt; any_conversion(const T&amp;); template &lt;typename T&gt; any_conversion(volatile T&amp;); template &lt;typename T&gt; any_conversion(T&amp;); #endif }; </pre><p> Or maybe the following is enough: </p> <pre class="wiki">struct any_conversion { #ifndef BOOST_NO_RVALUE_REFERENCES template &lt;typename T&gt; any_conversion(T&amp;&amp;); #else template &lt;typename T&gt; any_conversion(T&amp;); #endif }; </pre><p> I'm planning to make a patch which enables the recently introduced <code>is_convertible</code> code on gcc 4.5-4.6 with the above <code>any_conversion</code> modification. Does it make sense? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Michel Morin</dc:creator> <pubDate>Fri, 31 Aug 2012 01:12:11 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7251#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7251#comment:6</guid> <description> <p> I have some questions. </p> <p> First, here is the description of <code>is_convertible</code> from the C++11 Standard: </p> <blockquote> <p> Given the following function prototype: </p> <pre class="wiki">template &lt;class T&gt; typename add_rvalue_reference&lt;T&gt;::type create(); </pre><p> the predicate condition for a template specialization <code>is_convertible&lt;From, To&gt;</code> shall be satisfied if and only if the following code would be well-formed, including any implicit conversions to the return type of the function: </p> <pre class="wiki">To test() { return create&lt;From&gt;(); } </pre></blockquote> <p> <br /> </p> <p> In C++11, for a function type <code>Func</code>, <code>is_convertible&lt;Func, Func&amp;&gt;</code> returns true_type. But, on gcc 4.5-4.6, <code>Func&amp;&amp;</code> cannot be convertible to <code>Func&amp;</code>. My question is "What should <code>is_convertible&lt;Func, Func&amp;&gt;</code> return on gcc 4.5-4.6?" <br /><br /> </p> <p> Also, in C++03, what should <code>is_convertible&lt;Func, Func*&gt;</code> return? It would be reasonable to return true_type, since <code>is_convertible&lt;Func, Func*&gt;</code> returns true_type in C++11. But we can make another interpretation. Boost's interpretation of C++03 <code>add_rvalue_reference&lt;T&gt;</code> is just returning <code>T</code>. Accordingly, <code>declval&lt;T&gt;()</code> returns a value of <code>T</code>. So, </p> <pre class="wiki">template &lt;class T&gt; typename add_rvalue_reference&lt;T&gt;::type create(); To test() { return create&lt;From&gt;(); } </pre><p> is ill-formed when <code>From</code> is a function type. With this interpretation, <code>is_convertible&lt;Func, Func*&gt;</code> should return false_type. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Thu, 02 Aug 2018 10:56:59 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7251#comment:7 https://svn.boost.org/trac10/ticket/7251#comment:7 <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">obsolete</span> </li> </ul> <p> I believe this to be essentially obsolete now, please file a new issue on Github if not. </p> Ticket