[Issue 2466] New: -w error for homogeneous arithmetic is too stringent
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Nov 21 11:11:18 PST 2008
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 at digitalmars.com
ReportedBy: schveiguy at 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.
--
More information about the Digitalmars-d-bugs
mailing list