Boost C++ Libraries: Ticket #12275: bind fwds shared_ptr twice, invokes memfn with nullptr https://svn.boost.org/trac10/ticket/12275 <p> Behavior started in 1.60, due to bind/bind.hpp changes around forwarding and rvalues. Short sample is shown below. This limitation needs to be mentioned in the boost docs, or somehow alter bind to work like before. Bind 1.59 would print the ptr address twice. Bind 1.60 gets a nullptr on the second memfn call. Quick fix for this sample is to change tFunc to use shared_ptr&lt;...&gt;const&amp; such that it can't be forwarded. </p> <pre class="wiki">#include &lt;stdio.h&gt; #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/make_shared.hpp&gt; #include &lt;boost/bind.hpp&gt; #include &lt;boost/function.hpp&gt; using namespace boost; using tFunc = function&lt;bool(shared_ptr&lt;const Obj&gt;)&gt;; struct Obj { bool MF() const { printf("this %p\n", this); return true; } }; int main() { shared_ptr&lt;const Obj&gt; sptr = make_shared&lt;Obj&gt;(); tFunc BB; BB = bind(&amp;Obj::MF, _1); BB = bind(BB, _1) &amp;&amp; bind(&amp;Obj::MF, _1); BB(sptr); } </pre><p> Boost 1.59 </p> <pre class="wiki">this 0x117fc39 this 0x117fc39 </pre><p> Boost 1.60 </p> <pre class="wiki">this 0x117fc39 this (nil) </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12275 Trac 1.4.3 Jason Mancini <jayrusman@…> Fri, 17 Jun 2016 17:00:37 GMT <link>https://svn.boost.org/trac10/ticket/12275#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12275#comment:1</guid> <description> <p> Let's try that code sample again. :<sup>) Slightly adjusted for clarity. </sup></p> <pre class="wiki">#include &lt;stdio.h&gt; #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/make_shared.hpp&gt; #include &lt;boost/bind.hpp&gt; #include &lt;boost/function.hpp&gt; using namespace boost; struct Obj { bool MF() const { printf("this %p\n", this); return true; } }; using tFunc = function&lt;bool(shared_ptr&lt;const Obj&gt;)&gt;; int main() { shared_ptr&lt;const Obj&gt; sptr = make_shared&lt;Obj&gt;(); tFunc AA, BB; AA = bind(&amp;Obj::MF, _1); BB = bind(AA, _1) &amp;&amp; bind(&amp;Obj::MF, _1); BB(sptr); </pre> </description> <category>Ticket</category> </item> <item> <author>Jason Mancini <jayrusman@…></author> <pubDate>Fri, 17 Jun 2016 17:02:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12275#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12275#comment:2</guid> <description> <pre class="wiki">} </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Mon, 20 Jun 2016 17:49:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12275#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12275#comment:3</guid> <description> <p> Thanks for the report; should be fixed in <a class="ext-link" href="https://github.com/boostorg/bind/commit/6616add21dff43f573d51503ebad4d3fcbcb2619"><span class="icon">​</span>https://github.com/boostorg/bind/commit/6616add21dff43f573d51503ebad4d3fcbcb2619</a> </p> </description> <category>Ticket</category> </item> <item> <author>Jason Mancini <jayrusman@…></author> <pubDate>Mon, 20 Jun 2016 19:55:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12275#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12275#comment:4</guid> <description> <p> Wow quick turn-around! Confirmed fix works for both the sample and the actual application. Thanks! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Fri, 22 Jul 2016 17:27:27 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/12275#comment:5 https://svn.boost.org/trac10/ticket/12275#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 master. </p> Ticket