Bug 8950 – postblit not called on const static array initialization

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-03T00:12:57Z
Last change time
2023-03-29T12:08:32Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Denis Shelomovskii

Comments

Comment #0 by verylonglogin.reg — 2012-11-03T00:12:57Z
--- struct S { static int postblits = 0; this(this) const { ++postblits; } } void main() { auto s = S(); S[2] arr = s; assert(S.postblits == 2); // ok S.postblits = 0; const S[2] constArr = s; assert(S.postblits == 2); // failed: S.postblits == 0 S.postblits = 0; const S[2] constArr2 = arr; assert(S.postblits == 2); // failed: S.postblits == 0 S.postblits = 0; } ---
Comment #1 by pro.mathias.lang — 2020-05-15T03:50:17Z
The behavior of this has changed a bit. First, qualified postblits are deprecated. Taking away the qualified, the second test passes, but not the third one. However postblit is going to be deprecated in the future so I doubt this'll get fixed. Leaving open until the postblit deprecation though...
Comment #2 by bugzilla — 2020-08-09T08:43:59Z
Yes, this will get a WONTFIX.
Comment #3 by kinke — 2020-10-17T16:20:11Z
Copy ctors are currently (wrongly) ignored when copying static arrays: https://issues.dlang.org/show_bug.cgi?id=20365 This issue here is pretty bad and inconsistent - the postblit is called correctly for mutable copies and scalar non-mutable copies, only non-mutable static array copies ignore the postblit: void main() { static struct S { int x = 42; this(this) { x += 10; } } { S source; S mutableCopy = source; assert(mutableCopy.x == 52); const S constCopy = source; assert(constCopy.x == 52); } { S[1] source; auto mutableCopy = source; assert(mutableCopy[0].x == 52); const constCopy = source; assert(constCopy[0].x == 52); // fails immutable immutableCopy = source; assert(immutableCopy[0].x == 52); // fails } }
Comment #4 by razvan.nitu1305 — 2023-03-29T12:08:32Z
Issue 20365 has been fixed and kinke's code and the original provided code do not assert anymore. Closing as WORKSFORME.