[Issue 19507] New: auto ref infers lvalue for member of rvalue
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Dec 22 16:21:50 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19507
Issue ID: 19507
Summary: auto ref infers lvalue for member of rvalue
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: atila.neves at gmail.com
The code below manages to bind an rvalue to a ref parameter due to wrong `auto
ref` inference:
----------------
void main() {
Foo foo;
fun(foo.create);
fun(foo.create.i);
}
struct Foo {
int i;
Foo create() {
return Foo();
}
}
void fun(T)(auto ref T value) {
import std.stdio;
writeln("T: ", T.stringof, " ref? ", __traits(isRef, value));
}
----------------
This prints:
T: Foo ref? false
T: int ref? true
In the first case, it correctly sees that `create` returns a new value and
infers it's an rvalue, so `auto ref` is not `ref.
But in the second case it reverts to `ref`, despite it being a subpart of an
rvalue!
--
More information about the Digitalmars-d-bugs
mailing list