This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Idea to refine -Wtype-limits


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]