www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9989] New: destructor triggers creation of opAssign for structs

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

           Summary: destructor triggers creation of opAssign for structs
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com


--- Comment #0 from monarchdodra gmail.com 2013-04-25 03:51:08 PDT ---
As discussed here: https://github.com/D-Programming-Language/phobos/pull/1260

Declaring a destructor in a struct triggers the creation of an opAssign. It
shouldn't.

Note that it doesn't create a postblit (which is correct):

//--------
struct S
{
  ~this(){}
}
void main()
{
    S s;
    s.opAssign(s);  //OK, should fail.
    s.__postblit(); //Correctly fails.
}
//--------

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


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2013-04-25 06:28:40 PDT ---
https://github.com/D-Programming-Language/dmd/pull/1935

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |INVALID


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2013-04-26
00:50:15 PDT ---
The reason an opAssign is generated if a destructor is present is because
assignment can no longer just copy over the data. The destructor must be run,
and the generated opAssign ensures that. The generated opAssign looks like:

  S tmp = this;   // bit copy
  this = s;       // bit copy
  tmp.dtor();

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



--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2013-04-26 01:36:20 PDT ---
(In reply to comment #2)
 The reason an opAssign is generated if a destructor is present is because
 assignment can no longer just copy over the data. The destructor must be run,
 and the generated opAssign ensures that. The generated opAssign looks like:
 
   S tmp = this;   // bit copy
   this = s;       // bit copy
   tmp.dtor();
OK. it is sane behavior, and my fix was not correct. But, if so, current dmd generates wrong code for struct S. I filed new issue for the problem. Issue 9994 - Built-in generated opAssign should call dtor on assignment -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 26 2013