Bug 16146 – postblit is not called on struct creation with "{field:value}" syntax

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-06-09T11:17:00Z
Last change time
2017-01-16T23:25:17Z
Assigned to
nobody
Creator
ketmar

Comments

Comment #0 by ketmar — 2016-06-09T11:17:11Z
here is sample code: import std.stdio; struct X { int* rc; this (int n) { auto x = new int[](1); rc = x.ptr; *rc = n; } this (this) { writeln("postblit; rc=", *rc); ++*rc; } ~this () { writeln("dtor; rc=", *rc, "; will be ", *rc-1); --*rc; } void opAssign (X src) { assert(0); } // just in case } struct Boo { X st; } void boo (ref Boo boo) { writeln("boo"); } void foo (X fl) { writeln("foo"); version(bug) Boo b = { st: fl }; else auto b = Boo(fl); writeln("foo 001"); boo(b); writeln("foo exit"); } void main () { { auto fl = X(1); writeln("000"); foo(fl); } writeln("001"); } with normal code path the output is: 000 postblit; rc=1 foo postblit; rc=2 foo 001 boo foo exit dtor; rc=3; will be 2 dtor; rc=2; will be 1 dtor; rc=1; will be 0 001 with -version=bug the output is: 000 postblit; rc=1 foo foo 001 boo foo exit dtor; rc=2; will be 1 dtor; rc=1; will be 0 dtor; rc=0; will be -1 001 as we can see, postblit is not called when Boo is created with `{ st: fl }` syntax. this makes writing refcounted data types with this syntax impossible without ugly hacks.
Comment #1 by bitter.taste — 2016-12-20T19:33:51Z
Comment #2 by ketmar — 2016-12-21T00:56:24Z
yeah, seems to be fixed. tnx!
Comment #3 by github-bugzilla — 2016-12-22T07:53:27Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/5b2fb91bae4df298a82bc94565198827671664ef Fix issue 16146 - Postblit the values in struct literals. https://github.com/dlang/dmd/commit/d7e22deca67ca114ea37b0c7e9fa2e0d6adb9069 Merge pull request #6271 from LemonBoy/structfill Fix issue 16146 - Postblit the values in struct literals.
Comment #4 by github-bugzilla — 2016-12-27T14:41:19Z
Commits pushed to scope at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/5b2fb91bae4df298a82bc94565198827671664ef Fix issue 16146 - Postblit the values in struct literals. https://github.com/dlang/dmd/commit/d7e22deca67ca114ea37b0c7e9fa2e0d6adb9069 Merge pull request #6271 from LemonBoy/structfill
Comment #5 by github-bugzilla — 2017-01-16T23:25:17Z
Commits pushed to newCTFE at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/5b2fb91bae4df298a82bc94565198827671664ef Fix issue 16146 - Postblit the values in struct literals. https://github.com/dlang/dmd/commit/d7e22deca67ca114ea37b0c7e9fa2e0d6adb9069 Merge pull request #6271 from LemonBoy/structfill