www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6178] New: Struct inside the AA are not init correctly

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

           Summary: Struct inside the AA are not init correctly
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: jsancio gmail.com


--- Comment #0 from Jose Garcia <jsancio gmail.com> 2011-06-19 12:39:02 PDT ---


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 19 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6178



--- Comment #1 from Jose Garcia <jsancio gmail.com> 2011-06-19 12:45:41 PDT ---
Err -- Hit submit without a description...

I am going to assume that this was not already filed. If so please accept my
apologies.

If you create an AA that points to a struct the is not initialized properly. In
other word it is not the same as S.init. If this stays that way in can
completely confuse the dtor. For example:

import std.stdio;

struct Bug
{
   this(this) { writefln("%s postblit ctor called", var); }
   void opAssign(Bug rhs) { writefln("%s opAssign called", var); }
   ~this() { writefln("%s dtor called", var); }

   int var = 0;
}

void main()
{
   Bug[int] map;
   {
      map[0] = Bug(1);
   }
}

This yields the following output (you need -O or you will hit bug 6177):

dmd -w -O map_test.d && ./map_test
3 opAssign called
1 dtor called
3 dtor called

Where in the world is 3 coming from? You output may be slightly different.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 19 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6178


Jose Garcia <jsancio gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P1
          Component|DMD                         |druntime
           Platform|Other                       |x86
         OS/Version|Windows                     |Linux
           Severity|normal                      |blocker


--- Comment #2 from Jose Garcia <jsancio gmail.com> 2011-06-19 12:47:14 PDT ---
Moving it to druntime since it probably belongs there.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 19 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6178



--- Comment #3 from Jose Garcia <jsancio gmail.com> 2011-06-19 13:20:15 PDT ---
I am getting around this issue with:

enum : uint { TOKEN = 987654321 }

struct Bug
{
   ~this()
   {
      if(token == TOKEN) { ...}
   }

   private uint token = TOKEN;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 19 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6178


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm gmail.com
          Component|druntime                    |DMD


--- Comment #4 from kennytm gmail.com 2011-06-19 14:56:10 PDT ---
With an opAssign, an assignment to an AA struct will become something like

    Bug __aatmp1234 = void;   // <---
    __aatmp1234.opAssign(1);
    map.set(0, __aatmp1234);
    map[0].___postblit();

the '3' is likely due to the '<---' line. See bug 2451.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 19 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6178


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com


--- Comment #5 from Andrei Alexandrescu <andrei metalanguage.com> 2012-01-18
08:40:19 PST ---
Update - with the dmd from the head the example causes 

Internal error: backend/cgcs.c 162

If the destructor is commented out, the printed message on my machine is

-2084965984 opAssign called

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6178



--- Comment #6 from Jose Garcia <jsancio gmail.com> 2012-01-18 18:22:55 PST ---
Andrei,

Do you still get the compiler internal error with -0? See bug 6177.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6178



--- Comment #7 from Andrei Alexandrescu <andrei metalanguage.com> 2012-01-19
07:11:42 PST ---
(In reply to comment #6)
 Andrei,
 
 Do you still get the compiler internal error with -0? See bug 6177.

I don't understand the question. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 19 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6178


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx


--- Comment #8 from hsteoh quickfur.ath.cx 2012-03-16 08:10:42 PDT ---
I think he meant -O, not -0.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 16 2012