October 23, 2023
https://issues.dlang.org/show_bug.cgi?id=24196

          Issue ID: 24196
           Summary: _d_arraysetassign(S[],S.init): it not work  on struct
                    when it is “@disable this(this)”, dmd 2.105.2/ldc 1.35
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: dushibaiyu@foxmail.com

the struct when it is “@disable this(this)”, init the struct array use “T[] = T.init” it not work.

The S is @disable this(this); t[] = S.init. the t[0].i should be 42, but it was
not.

import std.stdio;
import core.memory;
struct S { int i = 42; @disable this(this); }

struct D { int i = 24;}


void main()
{
    writeln("@disable this(this);");
    auto ptr = GC.malloc(S.sizeof * 5);
    S[] t = cast(S[])(ptr[0..S.sizeof * 5]);
    writeln(t[0].i);
   t[] = S.init;
    // foreach(ref ts ; t){  // this is work to 42
    //     ts = S.init;
    // }
    writeln(t[0].i); // it should be 42, but it not!
    // assert(t[0].i  == 42);
    writeln("this(this);");
    ptr = GC.malloc(D.sizeof * 5);
    D[] d = cast(D[])(ptr[0..D.sizeof * 5]);
    writeln(d[0].i);
    d[] = D.init;
    writeln(d[0].i);

    writeln("this(this); D2");
    ptr = GC.malloc(D.sizeof * 5);
    D[] d2 = cast(D[])(ptr[0..D.sizeof * 5]);
    writeln(d2[0].i);
    D td;
    td.i = 78;
    d2[] = td;
    writeln(d2[0].i);

    assert(d[0].i  == 24);
    assert(d2[0].i  == 78);
    assert(t[0].i  == 42);
}


当禁用复制构造的结构体时。对其数组进行初始化(T[] = T.init),会失败。

--