Hi Bjoern,
Bjoern Milcke schrieb:
I came across the following piece of code:
String a;
xub_StrLen n = 0;
n += a.Len();
This breaks on Windows (due to -werror). Because of the warning:
warning C4244: '+=' : conversion from 'int' to 'USHORT', possible
loss of data (in the last line of the fragment)
By the holy standard, x += y where x, y are short works by promoting
x, y to int x', y', adding x' + y', converting int x' to short x'' and
assigning x'' back to x. MSC chose to warn about this (about the
potentially lossy "converting int x' to short x''" part).
I still think this warning doesn't make sense.
Indeed this might be an undesirable or at least discussable decision in
the C++ standard, because it is counter-intuitive.
However it is well possible (I haven't researched about it in-depth),
the decision to promote most values to at least int-size in arithmetic
expressions, has resolved a lot of other problems, the standard would
have faced otherwise.
IMHO a usable solution would be: Compilers should not warn, or at least
give the warning a different id, if all participants in such an
expression have the same original type which the compiler in many cases
should be able to recognise.
If more projects follow the example of OOo (and probably a few other
projects) to produce warning free code, hopefully in a few years
compiler-manufacturers are more aware of such problems. ;-)
Nikolai
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]