Bug 6470 – postblits not called on arrays of structs

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-08-11T17:05:00Z
Last change time
2015-06-09T05:11:56Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
hoganmeier

Comments

Comment #0 by hoganmeier — 2011-08-11T17:05:46Z
import std.stdio; struct F { long m; this(long arg) { m = arg; writeln("\tconstructed F ", arg); } ~this() { writeln("\tdestructed F ", m); } this(this) { writeln("\tcopied F ", m); } } void main() { F a = F(1); F b = F(2); write("F[] arr = [a, b];\n"); F[] arr = [a, b]; write("F[] arr3;\narr3 ~= a;\n"); F[] arr3; arr3 ~= a; write("F[2] arr2 = [a, b];\n"); F[2] arr2 = [a, b]; } Output: constructed F 1 constructed F 2 F[] arr = [a, b]; // no postblit called (no destructor either, see bug 2834) F[] arr3; arr3 ~= a; copied F 1 // only here it is called F[2] arr2 = [a, b]; // no postblit called destructed F 2 // b from arr2 destructed F 1 // a from arr2 destructed F 2 // b destructed F 1 // a Note that this issue ahs to be taken into consideration as well: http://www.digitalmars.com/d/archives/digitalmars/D/Static_array_initialization_113536.html
Comment #1 by k.hara.pg — 2011-09-09T09:35:14Z
Comment #2 by github-bugzilla — 2012-05-07T19:43:20Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/26aacf0b510d59f572122a55a9a74c071aab889c Issue 6470 - postblits not called on arrays of structs - Call postblits on array slice assign - Call postblits on array literal elements
Comment #3 by schveiguy — 2013-06-13T07:29:05Z
*** Issue 6182 has been marked as a duplicate of this issue. ***