DIP 1021--Argument Ownership and Function Calls--Community Review Round 1

David Bennett davidbennett at bravevision.com
Fri Jul 19 03:31:16 UTC 2019


On Friday, 19 July 2019 at 02:59:59 UTC, David Bennett wrote:
>
> Also, does it also check simple non-heap references, for 
> example would this become compile time error?
>
> ---
> @safe void f(scope ref int a, scope ref int b)
> {
>      a=1;
>      assert(b==1);
> }
> @safe void main()
> {
>     int i = 0;
>     f(i, i);
>     assert(i==1);
> }
> ---
>

Actually re-reading the DIP again it's says "multiple mutable 
references to the same object" not "multiple references to the 
same mutable object" so I'm guessing my example above would still 
compile with -dip1021 ?

If that's so I'm guessing this would be the simplest thing that 
would stop compiling?

---
@safe void f(scope ref int* a, scope ref int* b)
{
     *a=1;
     a = null;
     assert(*b==1);

}
@safe void main()
{
     int i = 0;
     scope int* a = &i;
     scope int* b = &i;
     f(a, b);
     assert(i==1);
     assert(a is null);
     assert(*b==1);
}
---




More information about the Digitalmars-d mailing list