Bug 24612 – Explicitly given `auto ref` parameter can’t bind by lvalue by value

Status
NEW
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-06-16T11:37:50Z
Last change time
2024-12-13T19:35:45Z
Assigned to
No Owner
Creator
Bolpat
Moved to GitHub: dmd#20469 →

Comments

Comment #0 by qs.il.paperinik — 2024-06-16T11:37:50Z
```d void f(T)(auto ref T x) {} void main() { int x; f!long(x); // Error: template `f` is not callable using argument types `!(long)(int)` } ``` This should instantiate `f` as `f!long(long x)`, as `int` converts to `long` and `cast(long)x` is an rvalue. I don’t know how far with implicit conversions this should go, but it should work for built-in integer and floating-point types. It should also work for class/interface types with inheritance relationship, and while binding those by `auto ref` is weird to do explicitly, such a binding might end up from templates that bind arbitrary type objects that happen to be class handles in the user’s code. Then: ```d Exception e = new Exception(""); f!Object(e); // Currently error, should be pass-by-value ``` With my proposed fix for Issue 24611, users could opt-into `ref` explicitly if they need to.
Comment #1 by robert.schadek — 2024-12-13T19:35:45Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20469 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB