Bug 23557 – Array concatenation ignores copy constructor

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-12-14T19:07:08Z
Last change time
2023-07-03T19:04:51Z
Assigned to
No Owner
Creator
Paul Backus
See also
https://issues.dlang.org/show_bug.cgi?id=23556, https://issues.dlang.org/show_bug.cgi?id=20879, https://issues.dlang.org/show_bug.cgi?id=23563

Comments

Comment #0 by snarwin+bugzilla — 2022-12-14T19:07:08Z
As of DMD 2.101.0, the following program compiles and runs successfully to completion: --- struct S { this(ref S) { assert(0); } } void main() { S[] a = [ S() ]; S[] b = a ~ a; } --- This program should assert at runtime when evaluating the expression `a ~ a`, but does not, because the copy constructors of a's elements are not called. If the copy constructor is changed to a postblit (`this(this)`), the program asserts at runtime, as expected. See also issue 23556, which affects appending to an array (~=), and issue 20879, which affected .dup and .idup.
Comment #1 by razvan.nitu1305 — 2022-12-16T08:30:24Z
This should be fixed by this lowering: https://github.com/dlang/dmd/pull/14550
Comment #2 by teodor.dutu — 2022-12-16T11:34:03Z
Yes, the lowering in https://github.com/dlang/dmd/pull/14550 fixes this issue.
Comment #3 by snarwin+bugzilla — 2023-07-03T19:04:51Z
Confirmed fixed as of DMD 2.104.0, presumably by the linked PR.