Add `__rvalue` as a new parameter storage class
Quirin Schroll
qs.il.paperinik at gmail.com
Thu Jan 23 01:15:43 UTC 2025
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)` returns `false` on them. Add trait `isRvalue`
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:
```d
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))`.
More information about the dip.ideas
mailing list