Boost C++ Libraries: Ticket #12019: Conversion from unique_ptr to shared_ptr is too broad https://svn.boost.org/trac10/ticket/12019 <p> The following program doesn't compile because the foo overload is ambiguous. This applies if boost::movelib::unique_ptr is used as well. It works if std::shared_ptr is used instead of boost::shared_ptr. </p> <p> $ cat foo.cpp #include &lt;boost/shared_ptr.hpp&gt; #include &lt;memory&gt; </p> <p> using boost::shared_ptr; using std::unique_ptr; using std::make_unique; </p> <p> template &lt;typename T&gt; class Provider { }; </p> <p> template &lt;typename T&gt; void foo(shared_ptr&lt;T&gt; ptr) { } </p> <p> template &lt;typename T&gt; void foo(unique_ptr&lt;Provider&lt;T&gt;&gt; ptr) { } </p> <p> class <a class="missing wiki">IntProvider</a> : public Provider&lt;int&gt; { }; </p> <p> void bar() { </p> <blockquote> <p> foo&lt;int&gt;(make_unique&lt;<a class="missing wiki">IntProvider</a>&gt;()); </p> </blockquote> <p> } $ g++ -std=c++14 -c foo.cpp foo.cpp: In function ‘void bar()’: foo.cpp:24:38: error: call of overloaded ‘foo(std::_MakeUniq&lt;<a class="missing wiki">IntProvider</a>&gt;::<span class="underline">single_object)’ is ambiguous </span></p> <blockquote> <p> foo&lt;int&gt;(make_unique&lt;<a class="missing wiki">IntProvider</a>&gt;()); </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> <p> foo.cpp:13:6: note: candidate: void foo(boost::shared_ptr&lt;X&gt;) [with T = int] </p> <blockquote> <p> void foo(shared_ptr&lt;T&gt; ptr) </p> <blockquote> <p> <sup> </sup></p> </blockquote> </blockquote> <p> foo.cpp:17:6: note: candidate: void foo(std::unique_ptr&lt;Provider&lt;T&gt; &gt;) [with T = int] </p> <blockquote> <p> void foo(unique_ptr&lt;Provider&lt;T&gt;&gt; ptr) </p> </blockquote> <p> The boost::shared_ptr&lt;T&gt; taking unique_ptr&lt;Y, D&gt; should be SFINAE'd away when unique_ptr&lt;Y, D&gt;::pointer isn't convertible to T*. </p> <p> The std::shared_ptr DR is <a class="reopened ticket" href="https://svn.boost.org/trac10/ticket/2399" title="#2399: Bugs: Python boost.mpi.Request.test() crashes (reopened)">#2399</a>: <a class="ext-link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2399"><span class="icon">​</span>http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2399</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12019 Trac 1.4.3 Tavian Barnes <tavianator@…> Thu, 25 Feb 2016 21:27:20 GMT <link>https://svn.boost.org/trac10/ticket/12019#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12019#comment:1</guid> <description> <p> Argh, messed up the formatting. Should read like this: </p> <p> --- </p> <p> The following program doesn't compile because the foo overload is ambiguous. This applies if boost::movelib::unique_ptr is used as well. It works if std::shared_ptr is used instead of boost::shared_ptr. </p> <pre class="wiki">$ cat foo.cpp #include &lt;boost/shared_ptr.hpp&gt; #include &lt;memory&gt; using boost::shared_ptr; using std::unique_ptr; using std::make_unique; template &lt;typename T&gt; class Provider { }; template &lt;typename T&gt; void foo(shared_ptr&lt;T&gt; ptr) { } template &lt;typename T&gt; void foo(unique_ptr&lt;Provider&lt;T&gt;&gt; ptr) { } class IntProvider : public Provider&lt;int&gt; { }; void bar() { foo&lt;int&gt;(make_unique&lt;IntProvider&gt;()); } $ g++ -std=c++14 -c foo.cpp foo.cpp: In function ‘void bar()’: foo.cpp:24:38: error: call of overloaded ‘foo(std::_MakeUniq&lt;IntProvider&gt;::__single_object)’ is ambiguous foo&lt;int&gt;(make_unique&lt;IntProvider&gt;()); ^ foo.cpp:13:6: note: candidate: void foo(boost::shared_ptr&lt;X&gt;) [with T = int] void foo(shared_ptr&lt;T&gt; ptr) ^ foo.cpp:17:6: note: candidate: void foo(std::unique_ptr&lt;Provider&lt;T&gt; &gt;) [with T = int] void foo(unique_ptr&lt;Provider&lt;T&gt;&gt; ptr) ^ </pre><p> The boost::shared_ptr&lt;T&gt; constructor taking unique_ptr&lt;Y, D&gt; should be SFINAE'd away when unique_ptr&lt;Y, D&gt;::pointer isn't convertible to T*. </p> <p> The std::shared_ptr DR is <a class="reopened ticket" href="https://svn.boost.org/trac10/ticket/2399" title="#2399: Bugs: Python boost.mpi.Request.test() crashes (reopened)">#2399</a>: <a class="ext-link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2399"><span class="icon">​</span>http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2399</a> </p> </description> <category>Ticket</category> </item> </channel> </rss>