Bug 13168 – cast(ref T) should work, along with support from opCast

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2014-07-20T18:31:19Z
Last change time
2024-12-13T18:22:24Z
Assigned to
No Owner
Creator
Andrei Alexandrescu
Moved to GitHub: dmd#18852 →

Comments

Comment #0 by andrei — 2014-07-20T18:31:19Z
Consider: void main() { int a; cast(ref uint) a = 42; } This doesn't compile. What people usually do is: void main() { int a; *cast(uint*) &a = 42; } but this is more dangerous and less tractable especially in safe code. Furthermore, opCast support should work seamlessly: struct A { int a; ref int opCast(int)() { return a; } } A x; cast(int) x = 42; // assigns to x.a This is confusing and should only work if the cast specifies ref: cast(ref int) x = 42; // fine, assign to x.a
Comment #1 by nick — 2024-03-18T12:41:39Z
*** Issue 20075 has been marked as a duplicate of this issue. ***
Comment #2 by robert.schadek — 2024-12-13T18:22:24Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18852 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB