DIP1000: Scoped Pointers

Dicebot via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Mon Aug 15 07:05:39 PDT 2016


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-announce/attachments/20160815/716194bf/attachment.sig>


More information about the Digitalmars-d-announce mailing list