November 21, 2008 [Issue 2466] New: -w error for homogeneous arithmetic is too stringent | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=2466 Summary: -w error for homogeneous arithmetic is too stringent Product: D Version: 1.036 Platform: PC OS/Version: Windows Status: NEW Keywords: diagnostic Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: schveiguy@yahoo.com The following code produces four warnings with -w: void foo() { char c; short s; byte b; int i; c = c + c; s = s + s; b = b + b; i = i + i; s = c + c; } outputs: warning - testbug.d(8): Error: implicit conversion of expression (cast(int)c + cast(int)c) of type int to char can cause loss of data warning - testbug.d(9): Error: implicit conversion of expression (cast(int)s + cast(int)s) of type int to short can cause loss of data warning - testbug.d(10): Error: implicit conversion of expression (cast(int)b + cast(int)b) of type int to byte can cause loss of data warning - testbug.d(13): Error: implicit conversion of expression (cast(int)c + cast(int)c) of type int to short can cause loss of data This is inconsistent. If the warning system is warning about adding two of the same type together might produce loss of data, yes that could happen, but why not the same warning for integers? I can certainly add two ints together and lose data if I don't assign it to a long. And if that warning was added, the warning system would flag way too much code. Also, the s = c + c; producing a loss of data warning is plain wrong. I think if you are adding two of the same type together, and assigning it to the same type or larger type, it should compile without warnings. -- |
November 21, 2008 [Issue 2466] -w error for homogeneous arithmetic is too stringent | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2466 jarrett.billingsley@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |DUPLICATE ------- Comment #1 from jarrett.billingsley@gmail.com 2008-11-21 13:28 ------- Yeah, I'm pretty sure this is a dup. *** This bug has been marked as a duplicate of 1977 *** -- |
Copyright © 1999-2021 by the D Language Foundation