Bug 4770 – structs don't correctly copy when alias this is used
Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-08-30T15:12:00Z
Last change time
2010-08-30T15:16:14Z
Assigned to
nobody
Creator
kieron_brown
Comments
Comment #0 by kieron_brown — 2010-08-30T15:12:05Z
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 by dsimcha — 2010-08-30T15:16:14Z
Dup of Bug 2943.
*** This issue has been marked as a duplicate of issue 2943 ***