[Issue 4770] New: structs don't correctly copy when alias this is used

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 30 15:12:17 PDT 2010


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

           Summary: structs don't correctly copy when alias this is used
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: kieron_brown at hotmail.com


--- Comment #0 from Kieron Brown <kieron_brown at hotmail.com> 2010-08-30 15:12:05 PDT ---
if alias this is used on a member value (whether simple, or another struct)
copying an instantiated struct no longer results in all struct members
being copied (only the aliased value is copied).

The version is Version D 2.048 (version text copied from changelog)

The problem is best illustrated by a minimal example:

----- self contained d sample starts -----
import std.stdio, std.math;

void main()
{
    auto p = Test(0.5, 0.5);
    assert(0.5 == p.a); // ok
    assert(0.5 == p.b); // ok
    Test q;
    //q = Test(0.5, 0.5);
    //
    // the above line can substitute
    // the one below and the same
    // problem occurs
    q = p;
    if (isNaN(q.b))
        printf("problem replicated\n");
    assert(0.5 == q.a); // ok
    assert(0.5 == q.b); // this fails
}

struct Test
{
    double a;
    double b;
    alias a this;
}
----- end of file -----

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