Bug 18953 – Win32: extern(C++) struct destructor not called correctly through runtime
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-06-07T05:45:54Z
Last change time
2018-06-25T20:13:21Z
Keywords
C++, industry
Assigned to
Manu
Creator
Rainer Schuetze
Comments
Comment #0 by r.sagitario — 2018-06-07T05:45:54Z
import core.stdc.stdio;
extern(C++)
struct S
{
int x;
~this() { printf("~S %x\n", x); }
}
void main()
{
S[] arr = new S[3];
arr[1].x = 1;
arr[2].x = 2;
arr.length = 1;
assumeSafeAppend(arr); // destroys arr[1] and arr[2]
printf("done\n"); // arr[0] destroyed by final GC later
}
The expected output is:
~S 2
~S 1
done
~S 0
Works for win64, but for win32 (both -m32 and -m32mscoff) I get
~S c0b831ff
~S c0b831ff
done
~S c0b831ff
This sounds like a job for that proposal you had where assigning a C++ method to a delegate would imply a shim function to perform the adaptation.
I don't really know how/where to hack that in, would you mind looking into that?
Comment #3 by turkeyman — 2018-06-15T07:12:33Z
Was this fixed by your last merged patch?
Comment #4 by r.sagitario — 2018-06-15T07:22:08Z
I added a test for this in some iteration, but it seemed it failed/crashed on Linux, so I removed it immediately to not complicate the PR.
I'll open a new PR with a test case...
Comment #5 by github-bugzilla — 2018-06-25T20:13:15Z