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