Opened 6 years ago
Closed 6 years ago
#12275 closed Bugs (fixed)
bind fwds shared_ptr twice, invokes memfn with nullptr
Reported by: | Owned by: | Peter Dimov | |
---|---|---|---|
Milestone: | To Be Determined | Component: | bind |
Version: | Boost 1.61.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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<...>const& such that it can't be forwarded.
#include <stdio.h> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> #include <boost/bind.hpp> #include <boost/function.hpp> using namespace boost; using tFunc = function<bool(shared_ptr<const Obj>)>; struct Obj { bool MF() const { printf("this %p\n", this); return true; } }; int main() { shared_ptr<const Obj> sptr = make_shared<Obj>(); tFunc BB; BB = bind(&Obj::MF, _1); BB = bind(BB, _1) && bind(&Obj::MF, _1); BB(sptr); }
Boost 1.59
this 0x117fc39 this 0x117fc39
Boost 1.60
this 0x117fc39 this (nil)
Change History (5)
comment:1 by , 6 years ago
comment:3 by , 6 years ago
Thanks for the report; should be fixed in https://github.com/boostorg/bind/commit/6616add21dff43f573d51503ebad4d3fcbcb2619
comment:4 by , 6 years ago
Wow quick turn-around! Confirmed fix works for both the sample and the actual application. Thanks!
Let's try that code sample again. :) Slightly adjusted for clarity.