Boost C++ Libraries: Ticket #3022: Automatic conversion from Y* to boost::shared_ptr<Y> with std::pair https://svn.boost.org/trac10/ticket/3022 <p> The assignment of std::pair&lt;X,Y*&gt; to std::pair&lt;X,boost::shared_ptr&lt;Y&gt; &gt; compiles without warning and implicitly converts a Y* to a boost::shared_ptr&lt;Y&gt;. I guess this has to do with: </p> <p> template&lt;class T&gt; class shared_ptr { ... template&lt;class Ap&gt; typename boost::detail::sp_enable_if_auto_ptr&lt; Ap, shared_ptr &amp; &gt;::type operator=( Ap r ) ... }; </p> <p> This behavior was witnessed under VC2005, VC2008, and gcc4.0.1. </p> <p> A minimal program demonstrating an evil consequence of this follows: </p> <p> int main() { </p> <blockquote> <p> int i = 2; boost::shared_ptr&lt;int&gt; j( new int ); </p> </blockquote> <blockquote> <p> <em>boost::shared_ptr&lt;int&gt; k = &amp;*j; </em> does not compile <em>std::pair&lt;int,boost::shared_ptr&lt;int&gt; &gt; v( i, &amp;*j ); </em> does not compile std::pair&lt;int,boost::shared_ptr&lt;int&gt; &gt; v = std::make_pair( i, &amp;*j ); <em> However, this compiles </em> kabum </p> </blockquote> <p> } </p> <p> Regards, </p> <blockquote> <p> Tobias </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3022 Trac 1.4.3 Peter Dimov Wed, 13 May 2009 19:25:27 GMT <link>https://svn.boost.org/trac10/ticket/3022#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3022#comment:1</guid> <description> <p> This is caused by std::pair's converting constructor: </p> <pre class="wiki">template&lt;class U, class V&gt; pair&lt;T1, T2&gt;::pair( U const &amp; u, V const &amp; v ): first( u ), second( v ) {} </pre><p> and, unfortunately, there is nothing shared_ptr can do to stop it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Wed, 13 May 2009 19:37:50 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3022#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3022#comment:2</guid> <description> <p> Sorry, I meant: </p> <pre class="wiki">template&lt;class U, class V&gt; pair&lt;T1, T2&gt;::pair( pair&lt;U, V&gt; const &amp; r ): first( r.first ), second( r.second ) {} </pre><p> The initialization of second (of type shared_ptr) from r.second (or type int*) is explicit and as such, it does succeed. </p> </description> <category>Ticket</category> </item> <item> <author>koelsch@…</author> <pubDate>Mon, 18 May 2009 06:10:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3022#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3022#comment:3</guid> <description> <p> Sorry, I did not think such a constructor exists. I'll check that the next time. Should I resolve the Bug or is this usually done by the maintainer? </p> <blockquote> <p> Tobias </p> </blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Tue, 01 Dec 2009 01:45:15 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3022#comment:4 https://svn.boost.org/trac10/ticket/3022#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">invalid</span> </li> </ul> Ticket