This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Idea to refine -Wtype-limits
- From: "Manuel López-Ibáñez" <lopezibanez at gmail dot com>
- To: "Gerald Pfeifer" <gerald at pfeifer dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 26 Nov 2007 03:10:02 +0100
- Subject: Re: Idea to refine -Wtype-limits
- References: <Pine.LNX.4.64.0711260040410.19271@acrux.dbai.tuwien.ac.at>
On 26/11/2007, Gerald Pfeifer <gerald@pfeifer.com> wrote:
>
> So, I got a "creative" idea. What if we disable this warning if comparing
> against 0U instead of 0? Then we could use #define DEFINE_FIRST 0U and
> avoid the warning for cases like this, without losing real diagnostics
> assuming that nobody would accidently write such code.
>
> Ah, and we wouldn't even have to adjust any of the messages in GCC, just
> the check itself. ;-)
>
> Thoughts?
>
I would prefer if the warning was avoided for an explicit cast of 0 to
unsigned, that is, for:
((unsigned int) 0) <= c
I am thinking about code such in PR11856:
template <typename t>
void f(t c) {
assert(0 <= c and c <= 2);
}
int main() {
f<unsigned char>(5);
}
It would be much easier to modify the above into:
template <typename t>
void f(t c) {
assert( t(0) <= c and c <= 2);
}
But I don't have any idea how this can be checked at the point where
the warning is generated. Perhaps your proposal is easier to
implement.
Cheers,
Manu.