Thread overview
[Issue 2282] New: Struct copy-constructor should call opAssign
Aug 14, 2008
d-bugmail
Aug 04, 2009
Don
Nov 23, 2009
Don
Nov 23, 2009
Koroskin Denis
Nov 23, 2009
Don
Nov 23, 2009
Koroskin Denis
August 14, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2282

           Summary: Struct copy-constructor should call opAssign
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: 2korden@gmail.com


opAssign isn't called upon copy-construction.

I think that the following:

struct Test {
    void opAssign(Test other) {
       // ...
    }
    // ...
}

Test t1;
Test t2 = t1;

should be translated into the following:

Test t1;
Test t2 = void;
t2 = t1;


-- 

August 04, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2282


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |
                 CC|                            |clugdbug@yahoo.com.au
           Severity|normal                      |enhancement




--- Comment #1 from Don <clugdbug@yahoo.com.au>  2009-08-04 06:44:30 PDT ---
This behaviour is by design. I'm marking it as an enhancement, but it should probably be closed as invalid. It's definitely not a wrong-code bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 11, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2282


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 23, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2282


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |INVALID


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2009-11-23 00:30:25 PST ---
Invalid: use postblit instead.
When the types are identical, this(this) gets called, not opAssign.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 23, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2282



--- Comment #3 from Koroskin Denis <2korden@gmail.com> 2009-11-23 02:43:39 PST ---
In D2, yes, but what about D1?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 23, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2282



--- Comment #4 from Don <clugdbug@yahoo.com.au> 2009-11-23 03:00:24 PST ---
(In reply to comment #3)
> In D2, yes, but what about D1?

The spec is quite clear:

"The assignment operator cannot be overloaded for rvalues that can be implicitly cast to the lvalue type." (operatoroverloading.html#Assignment).

And when I compile the initial code, I get a compiler error message which is clear and which is in perfect agreement with the spec:

bug.d(19): Error: function test.Test.opAssign identity assignment operator ove
rload is illegal

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 23, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2282



--- Comment #5 from Koroskin Denis <2korden@gmail.com> 2009-11-23 03:15:55 PST ---
Great, thanks!

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