Compiler warning and highlighting failure

Eric Springer eric at brictus.com
Sat Aug 15 13:48:22 UTC 2009


[Disclaimer: a non-kde developer here]

On Sat, Aug 15, 2009 at 12:48 AM, Stefan Valouch<stefan at valouch.de> wrote:
> Hi,
>
> While looking at compiler warnings from kdevelop, i stumbled upon an
> interesting warning:
> "comparison is always true due to limited range of data type"
> It is located here: kdevelop/debuggers/gdb/mi/milexer.cpp line 137 and looks
> as follows:
>  (this->*s_scan_table[ch < 128 ? ch : 128])(&kind);

It just looks like the developer wants to be explicit in not going
over the array bounds of s_scan_table. If you wanted to kill the
compiler warning, while still being explicit you could use qMin(ch,
(char) 128) -- but I haven't checked if there is any runtime overhead.
Might be best just to simplify it to 'ch'.

> If i recall correct, a chars value range is –128 to 127.
> As m_contents is a QByteArray, i assume that the char "ch" should be of type
> unsigned char.
> Am i correct?

I don't believe so. The difference between unsigned char and char is
more about how you interpret and use the data. And in this code file
they seem to be using it all as signed data.


>
> On the same position there's a slight bug in highlighting: In the shortened
> if-statement, the value for true (the "ch") is not highlighted (both
> kdevplatform and kdevelop from trunk).
> Screenshot:
> http://valouch.info/screen/kde/bugs/kdevelop/highlighting_and_compilerwarning_always_true.png
> Should i open a bugreport on this?

Looks like it

>
> btw: Just got an account for svn :-)
>
> Stefan




More information about the KDevelop-devel mailing list