March 08 [Issue 24433] New: Array value assignment is incorrect for structs with destructors and copy constructors | ||||
---|---|---|---|---|
| ||||
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. The bug appears to have been introduced in #14382 https://github.com/dlang/dmd/commit/d0a367e98cc31a2675a5fc41a150dd38089f1982#diff-c9a721f453e1e17d997f8603ca3e4e65c765f0ebf0dd1cfb972ddddc959bdbb1 -- |
Copyright © 1999-2021 by the D Language Foundation