DMD 2.100, bring ont he attribute soup

Nick Treleaven nick at geany.org
Sat May 28 10:55:17 UTC 2022


On Friday, 27 May 2022 at 21:09:49 UTC, deadalnix wrote:
>> void f(scope T);
>>
>> T v = new T; // can be stack allocated
>> f(v);
>
> I don't think this is a valid optimization, because DIP1000 
> cannot track indirections. Therefore, I could have an objects 
> within the subgraph reachable from `v` which escape and which 
> itself can reaches back to `v`.

Can you give an example? The following currently compiles:

```d
@safe @nogc:

class C {
     C g() => this;
}

//C f(C c); // error
C f(scope C c); // OK
//C f(scope C c) { return c.g; } // error

void main()
{
     scope c = new C(); // allocated on the stack, scope currently 
required
     f(c);
}
```

If I switch in the third version of `f`, I get an error with 
-dip1000:
scopeclass.d(7): Error: scope variable `c` assigned to non-scope 
parameter `this` calling scopeclass.C.g


More information about the Digitalmars-d mailing list