http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752

--- Comment #21 from David Stone <DeusExSophismata at gmail dot com> 2012-03-24 
21:25:08 UTC ---
Why was this patch rejected, and is there a way to improve it so that obviously
safe cases (such as PR52703) are not warned about without having to specify a
'-Wno-' option?

Yes, according to the standard (C++03 5/9), calculations done on variables
smaller than int are first promoted to int, then the calculation is done, then
the value is converted back to the target size. However, C++03 1.8/3, the
"as-if rule", states that it the program can't tell the difference, you can do
whatever you want (see my answer to a similar question on Stack Overflow here:
http://stackoverflow.com/questions/5563000/implicit-type-conversion-rules-in-c-operators/8935697#8935697).

The C++ standard does not require a diagnostic for this, and the apparent
behavior is identical. Therefore, there can be no appeals to the C++ standard
on the behavior of the warning.

Because this is a purely option warning for which gcc defines the rules, we
should define it to be useful. If gcc can prove that all of the values are
greater than 0 (for instance, if all of the values are unsigned prior to
implicit promotion or are positive integral constant expressions), then there
is no possibility of having a negative value. Thanks to signed integer overflow
being undefined, there is no risk of creating a negative value that way,
either. Therefore, we should not warn. Having to manually say "Turn off stuff
that no one could ever possibly want to see" seems like a sure way to make this
warning useless.

Reply via email to