Friends don't let friends use inout with scope and -dip1000
Atila Neves
atila.neves at gmail.com
Tue Aug 21 09:50:46 UTC 2018
On Monday, 20 August 2018 at 15:55:54 UTC, Kagamin wrote:
> On Monday, 20 August 2018 at 13:02:23 UTC, Atila Neves wrote:
>> On Monday, 20 August 2018 at 12:56:42 UTC, Kagamin wrote:
>>> [...]
>>
>> I need `return` for what exactly? Your code still compiles,
>> and my point is it shouldn't. It sure isn't memory safe.
>
> @safe:
> struct MyStruct
> {
> import core.stdc.stdlib;
> int* ints;
> this(int size) @trusted { ints = cast(int*) malloc(size); }
> ~this() @trusted { free(ints); }
> inout(int)* ptr() return inout { return ints; }
> }
>
> int* gInt;
> void f()
> {
> auto s=MyStruct(10);
> gInt=s.ptr;
> }
>
>> Error: address of variable s assigned to gInt with longer
>> lifetime
>
> Looks safe to me.
With dmd 2.081.2 on Arch Linux, the code above compiles with no
error message.
More information about the Digitalmars-d
mailing list