Consider:
struct TT { int a; ~this(); }
void testtt(TT tt) /* tt is actually passed by ref */
{
tt.a = 40;
/* tt is destructed here, g++ destructs it in caller */
}
void foot()
{
TT t;
t.a = 3;
testtt(t); /* a copy of t is made here, and passed by ref */
/* g++ destructs copy here */
}
What dmd is doing is not wrong, it just is not what g++ is doing. I do not know why this is not showing up as a bug at least with g++ ABI compatibility.
Comment #1 by dlang-bot — 2024-02-04T06:04:40Z
@WalterBright created dlang/dmd pull request #16145 "fix bugzilla Issue 24368 - destruction of parameter should be done by…" fixing this issue:
- fix bugzilla Issue 24368 - destruction of parameter should be done by caller
https://github.com/dlang/dmd/pull/16145
Comment #2 by ibuclaw — 2024-02-04T08:20:02Z
(In reply to Walter Bright from comment #0)
> What dmd is doing is not wrong, it just is not what g++ is doing. I do not
> know why this is not showing up as a bug at least with g++ ABI compatibility.
Because this only applies to `extern(D)` code?
As you've said, what D does isn't wrong, but no ABI incompatibilty is being broken here either. So I don't see the problem here. We don't *need* to copy everything g++ does.
Comment #3 by robert.schadek — 2024-12-13T19:33:01Z