Bug 20071 – ref locals

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-07-22T06:58:08Z
Last change time
2024-12-13T19:04:37Z
Assigned to
No Owner
Creator
Manu
Moved to GitHub: dmd#17916 →

Comments

Comment #0 by turkeyman — 2019-07-22T06:58:08Z
It's frustrating that we can only use `ref` for function arguments. I should be able to declare a local variable ref to capture the result of a ref function, or to simplify a long expression. ref int fun(); void test() { ref int refLocal = fun(); ref int resolveExpression = thing[10].something().member.x; } It feels very lame to use pointers in these cases. It may also change semantics of assignment expressions when using pointers.
Comment #1 by bugzilla — 2019-07-23T08:25:43Z
This is not allowed because it would make the memory safe checks in the compiler much harder.
Comment #2 by turkeyman — 2019-07-23T08:33:05Z
How so? ref is more restrictive than pointers if anything. The fact they can't be re-bound and don't mess with assignment semantics are desirable advantages. It's also another case of weird asymmetry which I've had to try and explain lots of times, and there's no explanation I can give. At very least it should be identical complexity?
Comment #3 by robert.schadek — 2024-12-13T19:04:37Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17916 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB