Challenge: write a reference counted slice that works as much as possible like a built-in slice

Stanislav Blinov stanislav.blinov at gmail.com
Tue Dec 14 13:51:57 UTC 2021


On Tuesday, 14 December 2021 at 12:53:29 UTC, Tejas wrote:
> On Tuesday, 14 December 2021 at 12:51:23 UTC, Stanislav Blinov 
> wrote:
>> On Tuesday, 14 December 2021 at 12:41:23 UTC, Tejas wrote:
>>> On Tuesday, 14 December 2021 at 12:25:30 UTC, Stanislav 
>>> Blinov wrote:
>>
>>>> Slap a @safe on that and it won't compile.
>>>
>>> That's what I did after reading your message, with the bonus 
>>> of slapping @safe on `S.__dtor` as well ;)
>>>
>>> ```d
>>> import std.stdio:writeln;
>>>
>>> struct S{
>>> 	@disable this();
>>> 	~this()@safe/*now @safe*/{
>>> 		writeln("dtor!");
>>> 	}
>>> }	
>>>
>>> void main()@safe/* now @safe*/{
>>> 	S s = void;
>>> }
>>> ```
>>>
>>> It defeated `@safe` ;_;
>>
>> Oh, right, S doesn't have any pointers. @safe only cares about 
>> void-initializing those.
>
> Should it be posted on [bug tracker](issues.dlang.org) ?

It could do with an enhancement IMO. Your code specifically isn't 
causing any UB, but it's easy to see how practical code would. 
E.g. plain integers may refer to memory as well as any pointer.


More information about the Digitalmars-d mailing list