This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Idea to refine -Wtype-limits
- From: Gabriel Dos Reis <gdr at cs dot tamu dot edu>
- To: Gerald Pfeifer <gerald at pfeifer dot com>
- Cc: gcc at gcc dot gnu dot org, Manuel López-Ibáñez <lopezibanez at gmail dot com>
- Date: 25 Nov 2007 21:26:21 -0600
- Subject: Re: Idea to refine -Wtype-limits
- References: <Pine.LNX.4.64.0711260040410.19271@acrux.dbai.tuwien.ac.at>
Gerald Pfeifer <gerald@pfeifer.com> writes:
| -Wtype-limits guards a very useful, in my experience, set of warnings
| including the following:
|
| warning: comparison of unsigned expression < 0 is always false
| warning: comparison of unsigned expression >= 0 is always true
|
| Based on these I identified and fixed several real bugs in Wine so far
| and I'd like to enable -Wtype-limits by default. However, there is one
| caveat: -Wtype-limits also warns about seemingly harmless code like
|
| bool f(unsigned i) {
| if( DEFINE_FIRST <= i || i <= DEFINE_LAST )
| return false;
| return true;
| }
|
| in case DEFINE_FIRST evaluates to 0.
|
| In applications like Wine there are a couple of such cases and it would
| not be good to remove the first half of the check to silence the warning
| because at a later point in time the DEFINE_FIRST might actually change,
| plus the simplification is not obvious looking at the source.
|
| 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 have no implementation strategy at the moment. But I do have a
request: Please, whatever you do, please, don't make it noisy with
template codes and `reasonable' codes. (We have had PRs for that
behaviour in template codes).
-- Gaby