Is this an rvalue reference problem?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at
Sun Dec 27 10:54:25 PST 2015

On Sunday, 27 December 2015 at 16:05:39 UTC, Gary Willoughby 
> void foo(ref int x)
> 	foo(y++);
> If I remove the post-increment of the y variable if works. Is 
> this an rvalue reference issue?

Yes, but more than that, what, exactly, would you expect from 
that? The order of operations with the postfix ++ operator and 
ref would probably lead to confusing results anyway, so better to 
disallow it and force you to be a bit more clear with the code.

> Should the error message be a little more helpful?

Yeah, probably.

A ref in D is only allowed on lvalues... lvalue gets its name 
from being on the left side of an equal sign when assigning, as 
opposed to rvalues which are on the right side of the equal sign 
when assigning.

So if

y++ = 0;

doesn't compile, it will complain "y++ is not an lvalue" because 
it can't work on the left side of that assignment.

ref in D is a proxy for assignment which is why it has this 

More information about the Digitalmars-d-learn mailing list