[Issue 19754] cast() sometimes yields lvalue, sometimes yields rvalue
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Mar 23 09:30:54 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19754
Mathias LANG <pro.mathias.lang at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pro.mathias.lang at gmail.com
--- Comment #3 from Mathias LANG <pro.mathias.lang at gmail.com> ---
> So the cast yields an lvalue.
Only for shared, and probably because its semantic are not defined.
If you replace this shared with `const` or `immutable`, of course this `cast`
is rejected, even if the error message is somewhat confusing ("Error: cannot
modify constant cast(int)x", instead of mentioning lvalue).
> This does not compile claiming that the result of cast is an rvalue. Should pass and use an lvalue.
I don't see any reason it should pass. If anything, the first example should be
disallowed. What you aim to do can be equally done by taking a pointer to the
qualified variable, and casting that pointer.
```
shared int x;
auto p = (cast(int*) &x);
```
--
More information about the Digitalmars-d-bugs
mailing list