crash when using &this in struct constructor

Eric geachte.eric at gmail.com
Wed Jul 18 19:47:17 UTC 2018


On Wednesday, 18 July 2018 at 12:10:18 UTC, baz wrote:

> Specs are clear : it's a global so it's evaluated at compile 
> time 
> (https://dlang.org/spec/declaration.html#global_static_init)
>
> Example code should not compile.

Indeed. Inside a function it does actually work.
And ofcourse for

class Test {
  List ls = 1;
}

it's going to make a static initializer which is then copied 
during construction of Test, so that's never going to work with 
the &this.



More information about the Digitalmars-d-learn mailing list