ahatanak wrote:

> For non-ARC, no matter what order we do the destruction, it still blows up if 
> you call the function more than once: the block itself gets destroyed when 
> the first call returns, and we never run the initialization again. The only 
> way to make it usable would be to do something like C++ lifetime extension to 
> make the block itself have static lifetime (along the lines of how `static 
> const A& a = A();` works).

A few thoughts:

1. This can be fixed if the block is copied via `__Block_copy` and assigned it 
to `b` after the static initialization. `b` then points to a heap block, so 
later calls are fine. But the captures have to be kept alive until the block is 
copied.
2.  Even without the `__Block_copy`, the function is well defined if it only 
runs once. I don't think anything in the standard makes the code invalid just 
because it can't be invoked more than once.

https://github.com/llvm/llvm-project/pull/199508
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to