Bug 9911 – postblit not called when function is returning a initialized struct
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-04-09T04:49:37Z
Last change time
2022-11-29T14:55:45Z
Assigned to
No Owner
Creator
luka8088
Comments
Comment #0 by luka8088 — 2013-04-09T04:49:37Z
I am not sure if this is a bug but the behavior is strange.
http://dpaste.dzfl.pl/c37e673f
module program;
import std.stdio;
struct S1 {
int i;
this (this) {
writeln("S1 postblit");
}
}
struct S2 {
S1 v;
C c1;
this (S1 v) {
this.v = v;
this.c1 = new C(&this.f);
}
this (this) {
writeln("S2 postblit");
this.c1 = new C(&this.f);
}
S1 f () {
return this.v;
}
}
class C {
S1 delegate () d;
this (S1 delegate () d) {
this.d = d;
}
}
auto f (S1 v) {
return S2(v);
}
void main () {
auto s1 = f(S1(5));
writeln(s1.c1.d().i, " == 5 ?");
}
Comment #1 by maxim — 2013-04-09T07:43:17Z
It looks like issue 9352 (delegate captures struct stack pointer which becomes invalid)
Comment #2 by razvan.nitu1305 — 2022-11-29T14:55:45Z
*** This issue has been marked as a duplicate of issue 9352 ***