On Tue, Jun 3, 2014 at 1:08 AM, Peter Zijlstra <pet...@infradead.org> wrote:
>
> Once upon a time GCC also did warns like that, but my compiler is silent
> :-(

You should be happy. The gcc warnings were shit.

Iirc, gcc literally at one point warned about things like

   unsigned int i;

   if (i < 5)

because that's comparing an unsigned type ("i") with an expression
having a signed type ("5"). Yes, technically true, but it's not
actually a useful warning.

That got fixed pretty quickly, but I think gcc *still* warns about things like

    unsigned int i;

    if (i >= 0 && i <= 6)
        ...

which is actually a very valid thing to do, and is commonly the result
of using a range-checking macro, or in general writing code so that it
is robust and doesn't care about the actual underlying type.

Warnings about robust code are f*cking broken, and easily worse than
not having the warning at all. Because it results in people removing
the range check.

Btw, -Wsign-compare still complains about

   int i;

   if (i < 0 || i > sizeof(i))
       return error;

which is another example of a f*cking broken warning. There is no way
to avoid that warning without making the code worse. That code is
_correct_, dammit, and anybody who thinks it should warn (or the
programmer should cast the sizeof to "int") is a tool and a moron.

End result: disabling "-Wsign-compare" is thus the only correct thing
to do. Sadly compiler writers don't seem to care too deeply about the
sanity of their warnings.

              Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to