Bug 24196 – _d_arraysetassign(S[],S.init): it not work on struct when it is “@disable this(this)”, dmd 2.105.2/ldc 1.35

Status
NEW
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-10-23T14:45:59Z
Last change time
2024-12-07T13:42:56Z
Assigned to
No Owner
Creator
dushibaiyu
Moved to GitHub: dmd#17466 →

Comments

Comment #0 by dushibaiyu — 2023-10-23T14:45:59Z
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),会失败。
Comment #1 by robert.schadek — 2024-12-07T13:42:56Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17466 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB