digitalmars.D.bugs - [Issue 17346] New: Inconsistent l/rvalue overload resolution
- via Digitalmars-d-bugs (62/62) Apr 24 2017 https://issues.dlang.org/show_bug.cgi?id=17346
https://issues.dlang.org/show_bug.cgi?id=17346 Issue ID: 17346 Summary: Inconsistent l/rvalue overload resolution Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: petar.p.kirov gmail.com As Steven mentioned in this forum post [1], given an overload that varies solely on ref, then rvalue arguments should go to the non-ref and lvalue arguments should go to the ref. A simple test indicates that the above rule is true, but only if the ref overload is non-const: struct X { int x; } struct Y1 { this(X x) { writeln("rvalue: ", x.x); } this(const ref X x) // const { writeln("const lvalue ref: ", x.x); } } struct Y2 { this(X x) { writeln("rvalue: ", x.x); } this(ref X x) // non-const { writeln("lvalue ref: ", x.x); } } import std.stdio; void main() { auto y1_rval = Y1(X(1)); auto x1_lval = X(2); auto y1_lval = Y1(x1_lval); // should call the ref-overload auto y2_rval = Y2(X(3)); auto x2_lval = X(4); auto y2_lval = Y2(x2_lval); // should call the ref-overload } Expected output: Rvalue: 1 const lvalue ref: 2 Rvalue: 3 Lvalue ref: 4 Actual output: Rvalue: 1 Rvalue: 2 Rvalue: 3 Lvalue ref: 4 [1]: http://forum.dlang.org/post/odl0e1$1qkq$1 digitalmars.com --
Apr 24 2017