On Friday, 6 May 2016 at 23:51:59 UTC, Steven Schveighoffer wrote:

Of COURSE D supports local ref variables:

struct RefVar(T)
  private T * var;
  this(ref T v) { var = &v; }
  auto get() { return *var; }
  alias this get;

ref get() return {...

Which is unsafe even if the ctor is marked trusted, the struct could be moved to a higher scope. But like in another thread, you can have a ref property in @safe code:

T v;
@property ref myRef(){return v;}

So why are ref locals disallowed? Now we have the return attribute on functions that take myRef by ref, can it still escape?

ref myRef = v;

Reply via email to