Bug 18457 – betterC - struct destructor is always called at function return

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-02-18T13:56:03Z
Last change time
2018-11-02T02:01:48Z
Keywords
betterC
Assigned to
No Owner
Creator
Johannes Nordhoff

Comments

Comment #0 by mephisto — 2018-02-18T13:56:03Z
D seems to have an optimization: If a struct is initialized in a function and is returned from the same function, the destructor will not be called at return. But: With betterC this optimization doesn't appear. Problem: This produces a different behaviour of betterC and non-betterC. an example code from file "source/app.d": ---- struct S { ~this() {} } S myFunction() { S s = S(); return s; } S myOFunction( S s) { return s; } extern( C) void main() {} ---- extraction from: $ dmd -vcg-ast source/app.d ---- S myFunction() { S s = S(); try return s; catch(Throwable __o3) { s.~this(); throw __o3; } } S myOFunction(S s) { try { return s; } finally s.~this(); } ---- extraction from: $ dmd -betterC -vcg-ast source/app.d ---- S myFunction() { S s = S(); try { return s; } finally s.~this(); } S myOFunction(S s) { try { return s; } finally s.~this(); } ----
Comment #1 by bugzilla — 2018-10-26T07:45:36Z
Comment #2 by iamthewilsonator — 2018-10-27T23:36:41Z
*** Issue 19244 has been marked as a duplicate of this issue. ***
Comment #3 by github-bugzilla — 2018-11-02T02:01:47Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/b19d37acc8d2e06fdbe907e3b8250a4ffdc46b04 fix Issue 18457 - betterC - struct destructor is always called at function return https://github.com/dlang/dmd/commit/52e6722ec8309eb3774571a4334226cca83cda34 Merge pull request #8872 from WalterBright/fix18457 fix Issue 18457 - betterC - struct destructor is always called at fun… merged-on-behalf-of: Sebastian Wilzbach <[email protected]>