Boost C++ Libraries: Ticket #7201: boost::make_shared clobbers libstdc++ std::thread https://svn.boost.org/trac10/ticket/7201 <p> This program fails to compile using g++ version 4.7.1. </p> <div class="wiki-code"><div class="code"><pre> <span class="cp">#include</span> <span class="cpf">&lt;functional&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;thread&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/smart_ptr.hpp&gt;</span><span class="cp"></span> <span class="kt">void</span> <span class="nf">demo_entry</span><span class="p">(</span> <span class="n">boost</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">demo_ptr</span> <span class="p">)</span> <span class="p">{</span> <span class="p">}</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span> <span class="p">{</span> <span class="k">auto</span> <span class="n">demo_ptr</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">make_shared</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="kr">thread</span> <span class="n">demo_thread</span><span class="p">(</span> <span class="n">demo_entry</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="n">ref</span><span class="p">(</span><span class="n">demo_ptr</span><span class="p">)</span> <span class="p">);</span> <span class="n">demo_thread</span><span class="p">.</span><span class="n">join</span><span class="p">();</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> I get the following error output: </p> <div class="wiki-code"><div class="code"><pre><span class="o">[</span><span class="m">100</span>%<span class="o">]</span> Building CXX object CMakeFiles/make_shared_repro.dir/make_shared_repro.cpp.o In file included from /home/ahmedtd/project/make-shared-repro/make_shared_repro.cpp:3:0: /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4/thread: In instantiation of <span class="s1">&#39;std::shared_ptr&lt;std::thread::_Impl&lt;_Callable&gt; &gt; std::thread::_M_make_routine(_Callable&amp;&amp;) [with _Callable = std::_Bind_simple&lt;void (*(std::reference_wrapper&lt;boost::shared_ptr&lt;int&gt; &gt;))(boost::shared_ptr&lt;int&gt;&amp;)&gt;]&#39;</span>: /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4/thread:133:9: required from <span class="s1">&#39;std::thread::thread(_Callable&amp;&amp;, _Args&amp;&amp; ...) [with _Callable = void (&amp;)(boost::shared_ptr&lt;int&gt;&amp;); _Args = {std::reference_wrapper&lt;boost::shared_ptr&lt;int&gt; &gt;}]&#39;</span> /home/ahmedtd/project/make-shared-repro/make_shared_repro.cpp:20:5: required from here /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4/thread:191:67: error: could not convert <span class="s1">&#39;boost::make_shared(Arg1&amp;&amp;, Args&amp;&amp; ...) [with T = std::thread::_Impl&lt;std::_Bind_simple&lt;void (*(std::reference_wrapper&lt;boost::shared_ptr&lt;int&gt; &gt;))(boost::shared_ptr&lt;int&gt;&amp;)&gt; &gt;; Arg1 = std::_Bind_simple&lt;void (*(std::reference_wrapper&lt;boost::shared_ptr&lt;int&gt; &gt;))(boost::shared_ptr&lt;int&gt;&amp;)&gt;; Args = {}]()&#39;</span> from <span class="s1">&#39;boost::shared_ptr&lt;std::thread::_Impl&lt;std::_Bind_simple&lt;void (*(std::reference_wrapper&lt;boost::shared_ptr&lt;int&gt; &gt;))(boost::shared_ptr&lt;int&gt;&amp;)&gt; &gt; &gt;&#39;</span> to <span class="s1">&#39;std::shared_ptr&lt;std::thread::_Impl&lt;std::_Bind_simple&lt;void (*(std::reference_wrapper&lt;boost::shared_ptr&lt;int&gt; &gt;))(boost::shared_ptr&lt;int&gt;&amp;)&gt; &gt; &gt;&#39;</span> make<span class="o">[</span><span class="m">2</span><span class="o">]</span>: *** <span class="o">[</span>CMakeFiles/make_shared_repro.dir/make_shared_repro.cpp.o<span class="o">]</span> Error <span class="m">1</span> make<span class="o">[</span><span class="m">1</span><span class="o">]</span>: *** <span class="o">[</span>CMakeFiles/make_shared_repro.dir/all<span class="o">]</span> Error <span class="m">2</span> make: *** <span class="o">[</span>all<span class="o">]</span> Error <span class="m">2</span> </pre></div></div><p> After deciphering the template error, it appears the problem stems from line 194 in the libstdc++ &lt;thread&gt; header, which has a non-namespace-qualified call to make_shared. For some reason, even though this code is declared in the <code>std</code> namespace, it is deciding to use boost::make_shared. </p> <p> This is particularly strange because at the point <code>&lt;thread&gt;</code> is processed by the compiler, no boost code has yet been included. </p> <p> I have no idea whether this is bug in boost::smart_ptr, libstdc++, or the compiler itself. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7201 Trac 1.4.3 t551@… Tue, 07 Aug 2012 04:04:59 GMT attachment set https://svn.boost.org/trac10/ticket/7201 https://svn.boost.org/trac10/ticket/7201 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">make-shared-repro.tar.gz</span> </li> </ul> <p> Zipped cmake project for the reproducing program. </p> Ticket Kohei Takahashi <flast@…> Sun, 12 Aug 2012 16:08:34 GMT <link>https://svn.boost.org/trac10/ticket/7201#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7201#comment:1</guid> <description> <p> It seems libstdc++'s bug, see <a class="ext-link" href="http://gcc.gnu.org/PR53872"><span class="icon">​</span>PR53872</a> . GCC 4.7.2/4.8.0 will fix this bug. </p> </description> <category>Ticket</category> </item> <item> <author>Kohei Takahashi <flast@…></author> <pubDate>Sun, 12 Aug 2012 16:09:29 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/7201#comment:2 https://svn.boost.org/trac10/ticket/7201#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">flast@…</span> added </li> </ul> Ticket t551@… Sun, 12 Aug 2012 20:17:51 GMT <link>https://svn.boost.org/trac10/ticket/7201#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7201#comment:3</guid> <description> <p> Ok, I'll work around it until that release. Thank you for finding that -- I had no idea that ADL was the magic word to search for. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Wed, 11 Dec 2013 17:18:53 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7201#comment:4 https://svn.boost.org/trac10/ticket/7201#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> Ticket