digitalmars.D.bugs - [Issue 24433] New: Array value assignment is incorrect for structs
- d-bugmail puremagic.com (40/40) Mar 08 https://issues.dlang.org/show_bug.cgi?id=24433
https://issues.dlang.org/show_bug.cgi?id=24433 Issue ID: 24433 Summary: Array value assignment is incorrect for structs with destructors and copy constructors Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: major Priority: P1 Component: druntime Assignee: nobody puremagic.com Reporter: artha samerion.com If a struct defines both (1) a destructor and (2) a postblit or copy constructor, assigning it as a value to a slice will produce an invalid result: ``` import std.stdio; struct Uncopiable { int value; ~this() { } disable this(const ref Uncopiable); } void testCopy(Uncopiable unc) {} void main() { auto a = Uncopiable(1); auto b = Uncopiable(2); //testCopy(a); // fails, alright auto c = [Uncopiable(3)]; c[] = a; writeln(c[0].value); // Prints 3 instead of 1 writeln(a.value); // Prints 3 instead of 1 } ``` Removing either the destructor or copy constructor fixes the above problem. The issue also occurs if the copy constructor is replaced with a postblit. https://github.com/dlang/dmd/commit/d0a367e98cc31a2675a5fc41a150dd38089f1982#diff-c9a721f453e1e17d997f8603ca3e4e65c765f0ebf0dd1cfb972ddddc959bdbb1 --
Mar 08