On Monday, 15 August 2016 at 21:25:22 UTC, Walter Bright wrote:
On 8/15/2016 6:54 AM, 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?

A local variable initialized with a scoped value will have 'scope' inferred for it.

What happens in that case ?

void test() {
scope rnd  = new Rnd; // reference semantic and stack allocated
Rnd rnd2;
 rnd2 = rnd;
         some_sneaky_function_that_saves_global_state(rnd);
}

or is that not even possible ? (sorry I'm still a noob in D).

Reply via email to