www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9911] New: postblit not called when function is returning a initialized struct

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9911

           Summary: postblit not called when function is returning a
                    initialized struct
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: luka8088 owave.net


--- Comment #0 from luka8088 <luka8088 owave.net> 2013-04-09 04:49:37 PDT ---
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 ?");
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9911


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru


--- Comment #1 from Maxim Fomin <maxim maxim-fomin.ru> 2013-04-09 07:43:17 PDT
---
It looks like issue 9352 (delegate captures struct stack pointer which becomes
invalid)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2013