Understanding DIP 1000 semantics -- Where's the bug?

Sebastiaan Koppe mail at skoppe.eu
Tue Sep 24 18:30:09 UTC 2019


On Tuesday, 24 September 2019 at 17:01:56 UTC, Olivier FAURE 
wrote:
> That's a bad comparison. Refs aren't equivalent to unqualified 
> pointers, they're equivalent to a scope pointers.

Where does it say that? Would be good though.

> By the way, with the following code:
>
>     @safe:
>
>     int* foo(scope int* x)
>     {
>         int* a = x;
>         return a;              // Compile error: scope variable 
> *a* may not be returned
>     }
>
>     void main() {
>         int* p;
>         {
>             int x;
>             p = foo(&x);
>         }
>         *p = 1;			// Memory corruption
>     }
>
> the compiler correctly identifies that the problem isn't 
> "foo(&x)", but "return a", and gives an appropriate error 
> message.

That is because scope is inferred on `int* a`.


More information about the Digitalmars-d mailing list