------- Additional Comments From neil at daikokuya dot co dot uk 2005-02-17 15:12 ------- Subject: Re: incorrect overflow warning
schlie at comcast dot net wrote:- > > ------- Additional Comments From schlie at comcast dot net 2005-02-17 14:33 > ------- > (In reply to comment #8) > > char x = 0x80; warning: value changes sign during integer type conversion > > Implying an analogous warning for all assignments between dissimilarly > signed variables (i.e. signed x; unsigned y; x = y;) which I believe are > considered "compatible"; and half of all unsigned hex constants being > assigned to signed types even if cast, as it's arguably the cast which > produces the virtual numerical over/underflow. > > (where although you're numerically correct, seems like a lot of noise?) Well it's certainly a matter of taste. char is arguably a special case as you cannot assign a value with the high bit set without creating the warning on some targets. But if you are assigning values with the high bit set then arguably you have in mind whether you are dealing with signed or unsigned values and should be explicit about signedness. As such like any warning it tends to expose sloppy thinking. Your x=y example is of course not the same; whether a value is changing sign or not is not knowable at compile time and probably rarely the case, so I agree complaining about that would be annoying. Some people have in the past requested command-line switches to generate warnings for any implicit integer conversion. I agree a singed <-> unsigned should not be on by default, though potentially narrowing conversions are debatably more appropriate to have on by default. Neil. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20019