Bug 24368 – destruction of parameter should be done by caller

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-02-03T19:13:38Z
Last change time
2024-12-13T19:33:01Z
Keywords
backend, C++, pull, wrong-code
Assigned to
No Owner
Creator
Walter Bright
See also
https://issues.dlang.org/show_bug.cgi?id=11382, https://issues.dlang.org/show_bug.cgi?id=14912
Moved to GitHub: dmd#20393 →

Comments

Comment #0 by bugzilla — 2024-02-03T19:13:38Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20393 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB