DIP 1016--ref T accepts r-values--Community Review Round 1

Manu turkeyman at gmail.com
Sat Nov 10 05:56:09 UTC 2018


On Fri, Nov 9, 2018 at 10:15 AM Q. Schroll via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Friday, 9 November 2018 at 02:25:08 UTC, Manu wrote:
> > I think it's reasonable that `out` could reject rvalues.
>
> I have a question about lifetime. Consider your example
>
>    ref int gun(return ref int y);
>
> The current state `ref` also means that the return value of `gun`
> has an address.
>
> Using `gun` on an rvalue, it makes an invisible variable in the
> caller's scope.
>
> Will
>
>    int* p = &(gun(10));
>
> compile and `p` be referencing the invisible variable?

That's not @safe, for obvious reasons.


More information about the Digitalmars-d mailing list