[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: always true warning

From: Bernd Strieder
Subject: Re: always true warning
Date: Fri, 22 Dec 2006 11:30:42 +0100
User-agent: KNode/0.10.1

Hello, wrote:

> is it possible to turn off -Walways-true warning for certain
> comparison?

No, only for whole compilation units is possible. This warning is based
on heuristics. Most often the programmer has overseen something, if it
is displayed. In the face of templates this heuristic fails more
easily, whenever a lazy programmer wants to catch signed and unsigned
with the same code. Programmer laziness is much harder to detect, no
sensible heuristics known to include with the compiler.

> I have a template with parameter of integral type, which can be both
> signed and unsigned and I'm testing the value for <0.. With -Wall
> (which I'm using by default) I always get a warning this comparison is
> always true when I use unsigned type as a parameter..
> Are there any workarounds?

The clean way means (partially) specializing your template, and remove
the comparisions from the code for unsigned. If your template itself is
too large, you could perhaps forward the member functions with those
comparision to other template functions, which you could specialize
more easily.

IMO -Wall is nice during development. Everybody else not ready to change
the code could just compile without -Wall. A comment in the code that a
bogus warning might be triggered easily should not be a big problem, if
you are really sure it is bogus.

Bernd Strieder

reply via email to

[Prev in Thread] Current Thread [Next in Thread]