ptr wrapper with dip1000
Steven Schveighoffer
schveiguy at yahoo.com
Tue Dec 19 15:37:14 UTC 2017
On 12/19/17 8:22 AM, vit wrote:
> struct Ptr{
> int* ptr;
>
> static Ptr create(scope return int* ptr)@safe{
> Ptr x;
> x.ptr = ptr;
> return x;
> }
>
> /++ This doesn't work:
> this(scope return int* ptr)scope @safe{
> this.ptr = ptr;
> }
> +/
> }
>
> void main()@safe{
> int i;
> auto x = Ptr(&i);
> auto y = Ptr.create(&i);
> }
I think this is a limitation of dip1000 that was not foreseen. I think
when you mark the parameter `return`, `this` isn't actually considered a
return value, is it? So it doesn't link the lifetime of ptr to the
lifetime of this, which it should.
Please file an enhancement request, this should be allowed.
-Steve
More information about the Digitalmars-d-learn
mailing list