Subject: [Boost-bugs] [Boost C++ Libraries] #12275: bind fwds shared_ptr twice, invokes memfn with nullptr
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-06-17 14:18:17
#12275: bind fwds shared_ptr twice, invokes memfn with nullptr
-----------------------------------------+---------------------
Reporter: Jason Mancini <jayrusman@â¦> | Owner: pdimov
Type: Bugs | Status: new
Milestone: To Be Determined | Component: bind
Version: Boost 1.61.0 | Severity: Problem
Keywords: |
-----------------------------------------+---------------------
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)
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12275> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC