ref parameters: there is no escape
Michel Fortin
michel.fortin at michelf.com
Sun Aug 14 11:46:16 PDT 2011
On 2011-08-14 16:55:08 +0000, dsimcha <dsimcha at yahoo.com> said:
> Right, but they can be proven safe if they pass locals by ref **to
> @safe functions**. I don't think there's any disagreement that @safe
> functions shouldn't be allowed to take the address of locals or
> parameters.
Actually, no, that's not safe by itself. Consider this:
ref int foo(ref int a) @safe
{
return a;
}
ref int bar() @safe
{
int a;
return foo(a);
}
And now 'bar' returns its local variable 'a' by ref, thanks to the
complicity of 'foo'. All this unsafety is perfectly @safe.
I think a @safe function shouldn't be allowed to return by ref one of
its parameter.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list