Boost C++ Libraries: Ticket #2951: Unwanted implicit conversion from std::auto_ptr to boost:;shared_ptr https://svn.boost.org/trac10/ticket/2951 <p> In boost 1.38, the explicit keyword was dropped from this constructor template in shared_ptr.hpp: </p> <p> template&lt;class Ap&gt; shared_ptr( AP r, typename boost::detail::sp_enable_if_auto_ptr&lt;Ap, int&gt;::type = 0 ): px( r.get() ), pn() { </p> <blockquote> <p> typename Ap::element_type * tmp = r.get(); pn = boost::detail::shared_count( r ); boost::detail::sp_enable_shared_from_this( pn, tmp, tmp ); </p> </blockquote> <p> } </p> <p> The explicit keyword was there in boost 1.34. This causes implicit conversions from auto_ptr to shared_ptr, which is undesirable. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2951 Trac 1.4.3 Peter Dimov Thu, 16 Apr 2009 22:32:25 GMT <link>https://svn.boost.org/trac10/ticket/2951#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2951#comment:1</guid> <description> <p> It should only allow implicit conversions from auto_ptr _rvalues_. Is this a problem? Do you have an example? </p> </description> <category>Ticket</category> </item> <item> <author>wmtan@…</author> <pubDate>Thu, 16 Apr 2009 23:01:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2951#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2951#comment:2</guid> <description> <p> It is definitely implicitly converting from an auto_ptr lvalue. We are using gcc3.4.5 (32 bit). We will be converting to gcc4.3 shortly, so I will check if the problem exists in gcc4.3. </p> <p> I will get back to you with an example shortly. </p> </description> <category>Ticket</category> </item> <item> <author>wmtan@…</author> <pubDate>Fri, 17 Apr 2009 17:15:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2951#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2951#comment:3</guid> <description> <p> <em>The following code compiles and runs. An auto_ptr lvalue is implicitly converted to a shared_ptr. This should not happen. This happens in gcc4.3 and gcc3.4, with no compiler options other than -I to include the boost header. </em></p> <blockquote> <p> #include &lt;memory&gt; </p> </blockquote> <p> </p> <blockquote> <p> #include &lt;iostream&gt; </p> </blockquote> <p> </p> <blockquote> <p> #include "boost/shared_ptr.hpp" </p> </blockquote> <blockquote> <p> struct X { </p> <blockquote> <p> int i; </p> </blockquote> <p> }; </p> </blockquote> <blockquote> <p> void f(boost::shared_ptr&lt;X&gt; sp) { </p> <blockquote> <p> std::cout &lt;&lt; sp-&gt;i &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> int main() { </p> <blockquote> <p> std::auto_ptr&lt;X&gt; ap(new X); ap-&gt;i = 1; f(ap); </p> </blockquote> <p> } </p> </blockquote> <p> ~ </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Fri, 17 Apr 2009 19:51:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2951#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2951#comment:4</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/52454" title="Bring back &#34;explicit&#34; on the auto_ptr rvalue constructor. Refs #2951.">[52454]</a>) Bring back "explicit" on the auto_ptr rvalue constructor. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2951" title="#2951: Bugs: Unwanted implicit conversion from std::auto_ptr to boost:;shared_ptr (closed: fixed)">#2951</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Sat, 18 Apr 2009 22:43:01 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2951#comment:5 https://svn.boost.org/trac10/ticket/2951#comment:5 <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> Merged to release in <a class="changeset" href="https://svn.boost.org/trac10/changeset/52472" title="Merge [52454] to release. Fixes #2951.">[52472]</a>. </p> Ticket