https://issues.dlang.org/show_bug.cgi?id=20876
Paul Backus <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #17 from Paul Backus <[email protected]> --- (In reply to Walter Bright from comment #16) > It seems like a simple solution would be: > > 1. if all fields take a const argument, then generate a const copy > constructor > > 2. if all fields take an immutable argument, then generate an immutable copy > constructor > > 3. otherwise, generate a mutable copy constructor The problem with this approach is that it is not always possible to find a single copy constructor signature that's compatible with all field copy constructors. For example: --- struct S { this(const ref S) {} this(shared ref S) {} } struct T { S s; // If all fields take a const argument, then // generate a const copy constructor. this(const ref T other) { this.s = other.s; } } void main() { { shared S original; S copy = original; // ok } { shared T original; T copy = original; // fails } } --- In this case, T needs to have two copy constructor overloads (a const one and a shared one) in order to correctly preserve the behavior of S. --
