DIP1000: Scoped Pointers

Rory McGuire via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Mon Aug 15 05:41:29 PDT 2016


On Mon, Aug 15, 2016 at 1:57 PM, ZombineDev via Digitalmars-d-announce <
digitalmars-d-announce at puremagic.com> wrote:

> On Monday, 15 August 2016 at 10:27:00 UTC, Dicebot wrote:
>
>> On Monday, 15 August 2016 at 07:19:00 UTC, lobo wrote:
>>
>>> When was it deprecated? I use it a lot and DMD 2.071.1 gives no warning.
>>>
>>
>> It was planned for removal because it was very un- at safe (no escaping
>> checks whatsoever) and as such was not better than library implementation.
>>
>
import std.stdio;

class Rnd {
this() {
writeln("created");
}
~this() {
writeln("destroyed");
}

int i;
}

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

rnd.i = 2;
assert(rnd2.i == 2);
return rnd2;
}

void main() {
writeln("start test");
auto v = test();
writeln("test exited", v);
}

Output:
start test
created
destroyed
segmentation fault (core dumped)  rdmd scoped_ref_class_semantics.d



> I suspected as much.
>
> Quite likely with DIP1000 implemented there will be no point in
>> deprecating it anymore.
>>
>
> +1 I think that would be great!
>
>
>
The above example should not compile after DIP1000? If so that will be
great!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-announce/attachments/20160815/1a439b41/attachment.html>


More information about the Digitalmars-d-announce mailing list