On Friday, 20 April 2018 at 09:24:26 UTC, Jonathan M Davis wrote:
The compiler assumes that a pointer is valid when determining whether code is @safe.
[...]
Basically, it verifies the @safety of pointers when they're created and then assumes that they're @safe after that.

Can't it do the same for ref returns? Unsafe stuff like returning a ref to a local is already disallowed, just like returning a pointer to a local. So the compiler checks the safety on creation, at least in some cases.

So, passing around a pointer is perfectly @safe, whereas taking the address of a ref return value to get a pointer is not.

It's still not clear to me how taking the address of a ref return is necessarily less safe than using a returned pointer. Do you maybe have an example in code that shows the difference?

It seems to me that refs and pointers are very much equivalent. I should always be able to turn one into the other.

Reply via email to