Add a new parameter storage class __rvalue
.
- For
extern(C++)
functions, mangles like the rvalue reference of the corresponding C++ compiler. - Inside the function, it’s like a
ref
, except that__traits(isRef)
returnsfalse
on them. Add traitisRvalue
to test if a parameter is__rvalue
.
It cannot bind lvalues except via __rvalue(lvalue)
. Any true rvalue, that is, any rvalue that’s not __rvalue(lvalue)
, is materialized in the caller and referenced, just like it would be for in
with big types under -preview=in
or for ref
under -preview=rvaluerefparam
. An __rvalue(lvalue)
is bound as if the lvalue
were passed to a normal ref
.
Example:
void f(__rvalue int x);
void main()
{
int n;
f(0); // good
f(n); // error: `n` cannot be bound to `__rvalue` parameter `x`
f(__rvalue(n)); // good
}
That would also enable structs’ move constructors to be defined with this(__rvalue typeof(this))
.