DIP 1016--ref T accepts r-values--Formal Assessment
Olivier FAURE
couteaubleu at gmail.com
Thu Jan 31 16:04:27 UTC 2019
On Thursday, 31 January 2019 at 02:10:05 UTC, Manu wrote:
> I still can't see a truck-sized hole.
I don't know if it's truck-sized, but here's another corner case:
int doubleMyValue(ref int x) {
x *= 2;
return x;
}
Point pt;
pt.x = 5;
pt.y = foobar();
doubleMyValue(pt.x);
assert(pt.x == 10);
Question: in the above code, will the assertion pass?
Answer: it depends on Point's implementation. If x is a member
variable, then yes. If it's a getter, then doubleMyValue will
take a rvalue and x won't be mutated and the assertion will fail.
I think this is a non-trivial conceptual problem.
More information about the Digitalmars-d-announce
mailing list