https://issues.dlang.org/show_bug.cgi?id=23747

--- Comment #3 from RazvanN <razvan.nitu1...@gmail.com> ---
(In reply to Mike S from comment #2)
> Ah noted, that is perhaps my mistake then. Looking at the specification
> again with this in mind, I now see how 'auto ref' is deducing the 'refness'
> of a function.
> 
> This means 'auto ref' snd 'ref auto' have different meanings then to be
> clear? 
> 
> - 'auto ref' deducing if it is possible to return by reference, and 'ref
> auto' explicitly indicating return by reference, and deduce the type (e.g.
> auto may be a double if possible return values are 1.0 and 1)

No, `auto ref` or `ref auto` is the same thing. If you want to have a ref
return type that is deduced you can simply omit the return type. The following
example showcases that `auto ref` and `ref auto` are the same thing:

// dmd -c test.d

auto ref fun()                                                                  
{
    int x;
    return x;
}

ref auto fun2()
{
    int x;
    return x;
}

int t;

auto ref fun3()
{
    return t;
}

ref auto fun4()
{
    return t;
}

ref fun5()
{
    return t;
}

ref fun6()
{
    int x;
    return x;     // error                                                      
}


pragma(msg, typeof(&fun));
pragma(msg, typeof(&fun2));
pragma(msg, typeof(&fun3));
pragma(msg, typeof(&fun4));
pragma(msg, typeof(&fun5));

--

Reply via email to