DIP1000: Scoped Pointers

Dicebot via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue Aug 16 09:34:05 PDT 2016


On 08/16/2016 07:26 PM, Patrick Schluter wrote:
> 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).

If `Rnd` is supposed to be a class, it won't compile because it would
mean escaping scope reference to non-scope variable (with DIP1000). If
it is a struct, it won't compile because you are trying to assign `Rnd*`
(pointer) to `Rnd` (value) :)

-------------- 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/20160816/d849efd9/attachment.sig>


More information about the Digitalmars-d-announce mailing list