scope variable values assigned to non-scope this.placeholder

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Mon Aug 6 20:29:29 UTC 2018


Hi Dlang community!

I've been playing with dip1000 and scope storage class and 
stumbled upon a strange error that I can't to understand yet. 
Here is minimized version of code that generates the error:

The link: https://run.dlang.io/is/rg2Odu
------------------------------
import std.stdio;
import std.range;
import std.algorithm;
@safe:
class C {
     const int*[] placeholder;

     this(scope int*[] values) {
         this.placeholder = values;
     }
}

void main()
{
     auto array = iota(0, 20).map!((int i) => new int(i)).array;

     auto c = new C(array);

     writeln(c.placeholder.map!(p => *p));
}
------------------------------

I'm not sure what I'm doing wrong, but from what I understand it 
should check 'this' lifetime to lifetime of scoped 'values' and 
error only in case when passed value has shorter lifetime than 
the container itself.

I'll be thankful if someone could explain what is wrong with this 
example.

Regards,
Alexandru.


More information about the Digitalmars-d-learn mailing list