[cfe-dev] blocks and lambdas
rjmccall at apple.com
Mon Feb 7 17:35:29 PST 2011
On Feb 7, 2011, at 5:24 PM, James Gregurich wrote:
> Is that because Block_copy is changing retain counts on captured values?
No, it's because block literals are initially allocated on the stack, so if you
return out of that stack frame, the block pointer becomes a dangling reference.
You could get the same result by passing a C++0x lambda around by
reference or pointer.
The problem is that generic code written for '0x lambdas will often assume that
copying a function object by value does a deep copy; however, copying a
block pointer is really just a pointer "copy", and the deep copy operation has
to be invoked manually.
More information about the cfe-dev