Hi,
I am a bit late with warning-freeness, I just now resynced against a
master build that contains warnings01 and pals. Maybe this problem here
is not new, but I didn't find anything about this.
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)
String is a typedef to UniString. UniString::Len() returns xub_StrLen.
So, here we have a xub_StrLen::operator+( xub_StrLen ), which should
work without conversion, no matter what xub_StrLen is. Actually,
xub_StrLen is currently a typedef to USHORT which is a typedef to
sal_uInt16 which is a typedef to "unsigned short" on Windows.
The only explanation I have for this is that there is no operator+= for
xub_StrLen, therefore the expression is expanded to:
n = (unsinged short)( (int)n + (int)(a.Len()) );
But why? There should be a lossless operator+= (and also +) for unsinged
short. And a typedef should be more or less an alias? And it is a POD
type, too.
Does anybody have an idea what the problem is here?
Rewriting this to
n = n + a.Len();
works. But it doesn't look much different.
Just checked:
unsigned short foo() { return 42; }
void bar()
{
unsigned short n = 0;
n += foo();
}
also creates the warning. So it doesn't have to do with typedefs. This
looks like a compiler bug to me.
Confused,
Bjoern
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]