Friends don't let friends use inout with scope and -dip1000

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Aug 20 13:18:07 UTC 2018


On Monday, August 20, 2018 3:43:46 AM MDT Nicholas Wilson via Digitalmars-d 
wrote:
> On Monday, 20 August 2018 at 09:31:09 UTC, Atila Neves wrote:
> > On Friday, 17 August 2018 at 13:39:29 UTC, Steven Schveighoffer
> >
> > wrote:
> >>> // used to be scope int* ptr() { return ints; }
> >>> scope inout(int)* ptr() inout { return ints; }
> >>
> >> Does scope apply to the return value or the `this` reference?
> >
> > I assumed the return value. I think I've read DIP1000 about a
> > dozen times now and I still get confused. As opposed to `const`
> > or `immutable`, `scope(T)` isn't a thing so... I don't know?
>
> What usually happens is that qualifiers to the left of the name
> apply to the return type and those to the right apply `this`. Not
> that that _should_ make any difference since lifetime ints ==
> lifetime this

I don't know what happens with scope with -dip1000, but that's not how D
works with any other qualifier that can affect the return type. If you don't
put parens on the qualifier on the return type, it refers to the this
pointer/reference. And arguably, if we're now putting scope on return types,
scope(T) should be a thing, and scope should have exactly the same behavior
as const, shared, etc. with regards to placement, or it's just going to
cause problems.

- Jonathan M Davis





More information about the Digitalmars-d mailing list