D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4770 - structs don't correctly copy when alias this is used
Summary: structs don't correctly copy when alias this is used
Status: RESOLVED DUPLICATE of issue 2943
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-30 15:12 UTC by Kieron Brown
Modified: 2010-08-30 15:16 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kieron Brown 2010-08-30 15:12:05 UTC
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 -----
Comment 1 David Simcha 2010-08-30 15:16:14 UTC
Dup of Bug 2943.

*** This issue has been marked as a duplicate of issue 2943 ***