[Issue 10272] New: opAssign() not invoked during variable declaration and initialization

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 4 23:50:12 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10272

           Summary: opAssign() not invoked during variable declaration and
                    initialization
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: pwil3058 at bigpond.net.au


--- Comment #0 from Peter Williams <pwil3058 at bigpond.net.au> 2013-06-04 23:50:09 PDT ---
Created an attachment (id=1219)
Demonstrate the opAssign() problem for struct template

The opAssign() operator is not called when the assignment is part of a variable
declaration for both the case where auto used and where the type is declared
explicitly. e.g.:

TestStruct t1 = TestStruct(arg);
TestStruct t2 = t1;

the opAssign() operator is not called in either of these cases.  But:

TestStruct t3;
t3 = TestStruct(arg);
t3 = t1;

the opAssign() operator is called in both cases.

This can have serious consequences if (for instance) the purpose of the
opAssign() method being defined was to ensured that the assignee and the
assignor did not share the same internal array.

The attached code demonstrates the problem.

-- 
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