rval->ref const(T), implicit conversions

Anon via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 18 13:39:09 PST 2016


On Monday, 18 January 2016 at 19:32:19 UTC, bitwise wrote:
> struct S;
>
> void func(ref S s);
> func(S());   // FINE
>
> void func(ref S s) @safe;
> func(S());   // ERROR

Isn't that backwards? I mean, @safe functions can't escape their 
parameters, so whether or not it is a temporary shouldn't matter 
to a @safe function. Meanwhile, non- at safe *can* escape 
parameters, and would fail or at least lead to problems if it 
tried to escape a ref to a temporary.

On the other hand, banning @safe code from passing a temporary as 
a ref parameter, while allowing it in non- at safe code makes a bit 
more sense to me, but seems less desirable.


More information about the Digitalmars-d mailing list