First Draft: ref For Variable Declarations

Dukc ajieskola at gmail.com
Sat Apr 13 10:24:18 UTC 2024


On Friday, 12 April 2024 at 20:43:50 UTC, Walter Bright wrote:
> https://github.com/WalterBright/documents/blob/984374ca885e1cb10c2667cf872aebc13b4c1663/varRef.md

This hits the same problem my old 
[DIP1022](https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1022.md) was addressing. What should happen if `ref` variable is initialised with a RValue? In my opinion it should be an error, but:
  - for `foreach` variables it is not
  - What if it's inside a template and is meant to be `ref` if 
possible but not otherwise?
The answer is the same as my DIP proposed: allowing `auto ref` 
for the variables.

Is `ref` allowed for static / global / `shared` storage class 
values?

All in all this is something that would sometimes be nice, and 
doesn't immediately make me come up with any reason it wouldn't 
work. However it allows to declare two variables that share 
memory, which gives me a feeling there might be some loophole 
that I missed. Hopefully Timon will have a look. If my worry 
turns out to be unfounded, I tend to be in favour of this.


More information about the dip.development mailing list