Bug 17128 – Wrong destructor call, if variables declared using tuple of types.
Status
RESOLVED
Resolution
DUPLICATE
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-01-30T12:39:31Z
Last change time
2023-06-27T02:55:20Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Jack Applegame
Comments
Comment #0 by japplegame — 2017-01-30T12:39:31Z
import std.stdio;
struct Foo {
int val = 0;
~this() {
writefln("destruct %s", val);
}
}
void bar(ARGS...)() {
ARGS args;
args[0].val = 1;
writefln("val = %s", args[0].val);
}
void main() {
bar!Foo();
}
Excpected output:
val = 1
destruct 1
But got:
destruct 0
val = 1
It seems that the compiler destructs 'args' immediately after definition, not at the end of the function.
Comment #1 by boris2.9 — 2023-06-27T02:55:20Z
*** This issue has been marked as a duplicate of issue 24010 ***