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

RazvanN <razvan.nitu1...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1...@gmail.com
         Resolution|---                         |INVALID

--- Comment #1 from RazvanN <razvan.nitu1...@gmail.com> ---
This bug report is invalid.

All of the `auto ref` functions work as expected. `Auto ref` does not mean "ref
+ type deduction", but rather "deduce if a function may return by ref + type
deduction". In all the situations presented, the compiler sees that it returns
a reference to the stack and therefore chooses to drop the ref and return by
value.

You can add this code and see the types of the functions:

pragma(msg, typeof(&Func1)); -> int function() ref
pragma(msg, typeof(&Func2)); -> int function() pure nothrow @nogc @safe

I guess the spec indeed is misleading by stating that "they become ref
functions if all return expressions are lvalues". Actually, its more like "they
become ref functions, if possible".

--

Reply via email to