[Issue 23747] 'auto ref' function return signature does not flag escaping a reference to local variable
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 27 12:10:10 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23747
RazvanN <razvan.nitu1305 at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |razvan.nitu1305 at gmail.com
Resolution|--- |INVALID
--- Comment #1 from RazvanN <razvan.nitu1305 at 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".
--
More information about the Digitalmars-d-bugs
mailing list