Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 08, 2007 Is this a bug in struct literals ? | ||||
---|---|---|---|---|
| ||||
Hello. I found that a question of following program in D-Language sled in huge BBS named 2ch in Japan. We think this is bug. In dmd 1.015ver. this bug has not yet fixed. If you has known these bugs, sorry. import std.stdio; struct A{int v;} void main(){ A a = A(10); if (a == a.init) writefln(a.v,"(a==a.init)"); else writefln(a.v,"(a!=a.init)"); a.v = 100; if (a == a.init) writefln(a.v,"(a==a.init)"); else writefln(a.v,"(a!=a.init)"); a = A(1000); if (a == a.init) writefln(a.v,"(a==a.init)"); else writefln(a.v,"(a!=a.init)"); } Result of execution: all comparisons in "if" are true. and all values of a.v are 10. |
June 08, 2007 Re: Is this a bug in struct literals ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to HATA | HATA wrote:
> Hello.
>
> I found that a question of following program in D-Language sled in huge BBS named 2ch in Japan.
> We think this is bug. In dmd 1.015ver. this bug has not yet fixed.
> If you has known these bugs, sorry.
>
> import std.stdio;
> struct A{int v;} void main(){ A a = A(10); if (a == a.init) writefln(a.v,"(a==a.init)"); else writefln(a.v,"(a!=a.init)"); a.v = 100; if (a == a.init) writefln(a.v,"(a==a.init)"); else writefln(a.v,"(a!=a.init)"); a = A(1000); if (a == a.init) writefln(a.v,"(a==a.init)"); else writefln(a.v,"(a!=a.init)"); }
>
> Result of execution:
> all comparisons in "if" are true.
> and all values of a.v are 10.
Definitely a bug. If you look at the (unoptimized) assembly code generated you can see that each comparison of a to a.init _writes 10 to a.v_ before the comparison (as though the code was "if ((a = a.init) && (a == a.init))".
(The optimized version also does this, but optimizes out the code for "a.v = 100" and "a = A(1000)" since they have no effect)
AFAIK this is a previously unknown bug. It seems to have been introduced in DMD 1.014 along with struct literals themselves.
|
June 08, 2007 Re: Is this a bug in struct literals ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frits van Bommel | Frits van Bommel wrote: > AFAIK this is a previously unknown bug. It seems to have been introduced in DMD 1.014 along with struct literals themselves. Entered into Bugzilla: http://d.puremagic.com/issues/show_bug.cgi?id=1262 |
June 08, 2007 Re: Is this a bug in struct literals ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frits van Bommel | > Entered into Bugzilla: http://d.puremagic.com/issues/show_bug.cgi?id=1262
Thank you for your reply and help.
|
Copyright © 1999-2021 by the D Language Foundation