[Issue 6768] New: Problem with init of struct members in presence of	templated opAssign
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Oct  4 19:15:16 PDT 2011
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=6768
           Summary: Problem with init of struct members in presence of
                    templated opAssign
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2011-10-04 19:14:34 PDT ---
module test;
import std.traits;
import std.stdio;
struct Point 
{
    int x, y;
    void delegate() dg;
    // void opAssign(void delegate() rhs)  // ok, x and y initialized
    // {
    //     dg = rhs;
    // }
    void opAssign(T)(T rhs) if (isDelegate!T)  // x and y left uninitialized
    {
        dg = rhs;
    }
    void test() { dg(); }
}
class Foo
{
    this() 
    { 
        point = { writefln("Point: %s", point); };  // assign delegate
    }
    Point point;
}
void main()
{
    auto foo = new Foo;
    foo.point.dg();    // x and y are initialized
    foo.point.test();  // but here x and y are not initialized (??)
    foo.point.dg();    // again, not initialized (??)
}
I don't understand how calling dg() directly or indirectly via test() prints
different results for x and y. If I use the non-templated version of opAssign
then both calls are fine, with x and y being zero-inited.
-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
    
    
More information about the Digitalmars-d-bugs
mailing list