Severe 2.084 regression when using staticArray on array of struct with class and bool member

ag0aep6g anonymous at example.com
Tue Feb 12 14:44:10 UTC 2019


On 12.02.19 15:06, Per Nordlöw wrote:
> class C
> {
>      this(int i) { this.i = i; }
>      int i;
> }
> 
> struct S
> {
>      C c;
>      bool b;                  // removing this prevents bug
> }
> 
> void main()
> {
>      import std.stdio : writeln;
>      import std.array : staticArray;
> 
>      auto c = new C(42);
> 
>      const S[1] s1 = [S(c)].staticArray;
>      const S[1] s2 = [S(c)];
> 
>      writeln(cast(void*)s1[0].c);
>      writeln(cast(void*)s2[0].c);
> 
>      assert(s1[0].c is
>             s2[0].c);
> }

Ouch. That looks bad. A reduction:

----
struct S
{
     ulong c;
     bool b;                  // removing this prevents bug
}

void main()
{
     S[1] a = [S(42)];
     assert(a[0].c == 42); /* Passes. */
     f(a);
}

void f(S[1] a)
{
     assert(a[0].c == 42); /* Fails. */
}
----

Fails since 2.070. https://run.dlang.io/is/LBhn4l


More information about the Digitalmars-d mailing list