Static inline field initialization

Jonas Mminnberg via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 22 04:50:50 PDT 2017


Because of D's static initialization of members, this assert 
fails:

class Test {
     ubyte[] buf = new ubyte[1000];
}

void main() {
     auto a = new Test();
     auto b = new Test();
     assert(a.buf.ptr != b.buf.ptr);
}

This is bad, since;
* It is not how C++ works
* It introduces silent sharing of data
* It's usually not what you want

Shouldn't this at least generate a warning, or ideally not be 
allowed?



More information about the Digitalmars-d mailing list