auto ref is on the docket
via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jun 23 02:47:47 PDT 2015
On Monday, 22 June 2015 at 18:10:11 UTC, Andrei Alexandrescu
wrote:
> On 6/22/15 9:54 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?=
> <schuetzm at gmx.net>" wrote:
>> `auto ref` without a working `scope` implementation is unsafe.
>
> I'm unclear on this. With the existence of the return
> attribute, what's unsafe about auto ref? -- Andrei
DIP25 _is_ a working `scope` implementation, for that matter,
albeit incomplete. (Strictly speaking, it's not the `return`
attribute that makes it safe, but the fact that under this
proposal `ref` implies what `scope` was originally supposed to
mean.)
You're right that if DIP25 is all we'll ever get (i.e. the
`scope` keyword will never have any meaning), then `auto ref`
might not be so bad a choice, although it still leaves the fact
that it does something different for template and non-template
functions. But it would create other inconsistencies with other
kinds of references, e.g.
void bar(ref MyStruct s);
void foo(MyClass c);
void baz() {
MyStruct s;
Scoped!MyClass c;
bar(s); // safe
foo(c); // not safe, reference may escape
}
For consistency, I would much prefer if `ref` and scope-ness were
kept independent, because they are orthogonal concepts. Why
should one kind of reference imply `scope`, but not others?
More information about the Digitalmars-d
mailing list