www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19507] New: auto ref infers lvalue for member of rvalue


          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 puremagic.com
          Reporter: atila.neves gmail.com

The code below manages to bind an rvalue to a ref parameter due to wrong `auto
ref` inference:

void main() {
    Foo foo;

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

Dec 22 2018