D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9911 - postblit not called when function is returning a initialized struct
Summary: postblit not called when function is returning a initialized struct
Status: RESOLVED DUPLICATE of issue 9352
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-09 04:49 UTC by luka8088
Modified: 2022-11-29 14:55 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description luka8088 2013-04-09 04:49:37 UTC
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 Maxim Fomin 2013-04-09 07:43:17 UTC
It looks like issue 9352 (delegate captures struct stack pointer which becomes invalid)
Comment 2 RazvanN 2022-11-29 14:55:45 UTC

*** This issue has been marked as a duplicate of issue 9352 ***