On 08/15/2016 04:54 PM, Rory McGuire via Digitalmars-d-announce wrote:
> okay nice, so that code would not compile but code such as:
> void test() {
> scope rnd  = new Rnd; // reference semantic and stack allocated
> auto rnd2 = rnd;
>         some_sneaky_function_that_saves_global_state(rnd);
> }
> would still not be checked. And would crash inexplicably at the point
> the global was accessed?

some_sneaky_function_that_saves_global_state would have to be declared
as `some_sneaky_function_that_saves_global_state(scope Rnd rnd)` to be
allowed to use rnd as argument which prevents escaping to globals.

What would still be the problem is if `Rnd` contains reference to
another class internally (which gets manually destroyed when Rnd is
destroyed) and `some_sneaky_function_that_saves_global_state` saves it
instead - because by current design `scope` is a storage class and not
transitive.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to