defect when using 'alias this' in a struct?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Aug 30 10:19:10 PDT 2010
On Mon, 30 Aug 2010 13:12:00 -0400, Kieron Brown
<kieron_brown at hotmail.com> wrote:
> I have used alias this and found odd behaviour in complex code.
>
> I tracked the problem down and was able to replicate it
> with a much simpler case as given below.
>
> I'm new to D (but have read TDPL).
> Is this my mis-understanding or a defect?
>
> Many thanks, Kieron
>
> ----- 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 gave same
> // error when subst for
> // the line below
> 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;
> }
Yes, that's a bug.
-Steve
More information about the Digitalmars-d-learn
mailing list