November 11, 2020 [Issue 21349] copy and postblit constructors aren't compatible | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21349 --- Comment #10 from RazvanN <razvan.nitu1305@gmail.com> --- (In reply to Paul Backus from comment #2) > This is an enhancement request, not a bug. Per the language spec: > > > For backward compatibility reasons, a struct that defines both a copy constructor and a postblit will only use the postblit for implicit copying. > > Source: https://dlang.org/spec/struct.html#struct-postblit > > You can work around this by placing sOld in a union, since unions do not have generated postblits: > > struct C > { > union { SOld sOld; } > SNew sNew; > > this(ref C other) { > pragma(inline, false); > sOld = other.sOld; > sNew = other.sNew; > } > } > > Of course, if SOld has any other special member functions, such as a destructor or identity opAssign overload, you will have to implement those manually for C as well. A better solution would be to simply disable the postblit in C and everything will work as you expect it. -- |
November 11, 2020 [Issue 21349] copy and postblit constructors aren't compatible | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21349 --- Comment #11 from RazvanN <razvan.nitu1305@gmail.com> --- I am inclined to close this as INVALID as the issue is easy to fix by disabling the postblit in C, however, I am going to wait for further objections. -- |
November 17, 2020 [Issue 21349] copy and postblit constructors aren't compatible | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21349 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |INVALID -- |
Copyright © 1999-2021 by the D Language Foundation