Bug 5737 – postblit not called for locals initialized from ref functions

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-03-15T01:54:00Z
Last change time
2012-05-07T19:40:20Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
samukha

Comments

Comment #0 by samukha — 2011-03-15T01:54:18Z
struct S { static int destroyed; static int copied; this(this) { copied++; } ~this() { destroyed++; } } S s; ref S foo() { return s; } void main() { { auto s2 = foo(); } assert(S.copied == 1); // fail, s2 was not copied; assert(S.destroyed == 1); // ok, s2 was destroyed } The destructor is called on s2, though s2 has not been postblit(ted?). Maybe the same as other struct lifetime bugs.
Comment #1 by kiithsacmp — 2012-03-18T02:45:08Z
Confirmed to still happen with DMD 2.058 .
Comment #2 by k.hara.pg — 2012-05-04T23:30:37Z
*** Issue 8045 has been marked as a duplicate of this issue. ***
Comment #3 by k.hara.pg — 2012-05-04T23:31:21Z
Comment #4 by github-bugzilla — 2012-05-07T18:10:45Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/70cbf1b9fb947a7abe920836e0b5746a39254ac0 fix Issue 5737 - postblit not called for locals initialized from ref functions https://github.com/D-Programming-Language/dmd/commit/7f18602f38082d8b837112fed1d5d10b222e3b87 Merge pull request #927 from 9rnsr/fix_postblit Issue 5737 & 6199 - fix postblit call with ref return