Array append ignores copy constructor · Issue #17454 · dlang/dmd (original) (raw)
Paul Backus (@pbackus) reported this on 2022-12-14T19:02:26Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=23556
CC List
- Steven Schveighoffer (@schveiguy)
- Teodor Dutu
Description
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() ]; auto p = a.ptr; // append until reallocation while (a.ptr == p) a ~= S(); // no assert }
This program should assert at runtime when the array is reallocated, but does not, because the copy constructors of the array'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 20879, which affected .dup and .idup.