The following code compiles and correctly resolves the lvalue vs. non-lvalue overloading:
import std.stdio;
void doStuff(const ref int i) {
writeln("Doing stuff by ref.");
}
void doStuff(const int i) {
writeln("Forwarding to ref overload.");
doStuff(i);
}
void main() {
doStuff(1);
}
Similar code also works for classes and arrays. It seems to be broken for structs, though. The following code is rejected:
import std.stdio;
struct S {}
bool fun(const ref S rhs) {
return true;
}
bool fun(const S rhs) {
return fun(rhs);
}
test9.d(12): Error: function test9.fun called with argument types:
((const(S)))
matches both:
test9.fun(ref const const(S) rhs)
and:
test9.fun(const const(S) rhs)
Comment #1 by k.hara.pg — 2011-06-24T04:48:56Z
*** Issue 6201 has been marked as a duplicate of this issue. ***
Comment #2 by k.hara.pg — 2011-06-24T04:54:00Z
This issue is part of bug5889. Add 'Depends on'.
Comment #3 by yebblies — 2012-01-31T07:46:56Z
*** Issue 7409 has been marked as a duplicate of this issue. ***
Comment #4 by lovelydear — 2012-04-20T09:10:43Z
Compiles on 2.059 Win32
Comment #5 by jens.k.mueller — 2012-04-22T13:30:29Z
Indeed. The issue seems to be fixed.
Comment #6 by k.hara.pg — 2012-04-22T16:38:58Z
*** This issue has been marked as a duplicate of issue 5889 ***