[Bug c/66773] sign-compare warning for == and != are pretty useless

segher at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 2 17:51:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66773

--- Comment #24 from Segher Boessenkool <segher at gcc dot gnu.org> ---
(In reply to Daniel Marjamäki from comment #23)
> > If the user expects C to provide tests for "mathematically different", the
> user has some learning to do.
> 
> I believe most users can appreciate this. But few users fully understand the
> integer conversions. I think it's dangerous. :-(

But deleting or disabling the sign compare warnings will not help this.

> > If, as I said, the user uses explicit casts, that's not good.  Much better
> already is to use implicit casts, as I said; and much better than that is
> to fix the problems at the root (use proper types everywhere), as I said.
> 
> You are de-facto advocating explicit casts because that is how everybody
> fixes these.

No, I am not; and no, not everyone uses casts to shut up these warnings.
Too many people do, certainly, but not even the majority.

> The advice to use proper types is good, in my opinion everybody tries to do
> that. However as far as I see it's impossible in practice to never mix
> signed and unsigned types in real projects.
> 
> > There is no simple fix, so GCC cannot give good guidance.
> 
> Then people just blindly use explicit casts.. and I dislike that.

Sure, me too.  Do you see a way we can discourage people from doing that?


More information about the Gcc-bugs mailing list