Bug 21036 – wrong code for non-pod types when compiled function with variadic static array

Status
NEW
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-07-11T03:25:55Z
Last change time
2024-12-13T19:10:05Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Илья Ярошенко
Moved to GitHub: dmd#19744 →

Comments

Comment #0 by ilyayaroshenko — 2020-07-11T03:25:55Z
import std.stdio; struct S { void* ptr; this(this){pragma(inline, false); writeln("cp");} ~this(){pragma(inline, false); writeln("des");} } auto bar(S[2] a...) { return a; } void main() { bar(S.init, S.init); } $ dmd -run test.d cp cp des des des des des des Expected 4 des, instead of 6.
Comment #1 by uplink.coder — 2020-07-16T14:08:57Z
It looks like the dtor is called on compiler created temporaries as well as on the actual arguments.
Comment #2 by uplink.coder — 2020-08-24T15:18:44Z
I assume the fix for this is to not call the dtors on compiler created temporaries. Let's see where that leads.
Comment #3 by kinke — 2021-07-13T12:12:02Z
It works as expected with an explicit array literal, i.e.: void main() { bar([S.init, S.init]); } In that case, the AST contains an ArrayLiteralExp with 2 StructLiteralExp elements. In the problematic case, the generated ArrayLiteralExp contains 2 temporaries - apparently for destruction, but the 2 elements are both rvalues and are supposed to be moved, so no destruction/temporaries necessary.
Comment #4 by robert.schadek — 2024-12-13T19:10:05Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19744 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB