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

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
I understand the distinction, but I don't think it would be helpful to try to
make it in the implementation of the warning, for a few reasons:

1) It's too subtle for non-expert programmers to understand.
2) It's unclear under what conditions the warning should or should not be
issued.  What if the controlling expression evaluates to zero but is not a
constant expression?  With or without optimization?
3) Avoiding the warning would require removing the implementation from the
front end and adding it to the middle-end, which tends to lead to
inconsistencies and both false positives and negatives.  (This isn't an
argument against also handling the overflow in the middle-end, as
-Wstrict-overflow does, but rather one against removing it from the front end.)
4) There are a number of similar warnings that behave the same way (e.g.,
-Wshift-negative-value, -Wshift-count-overflow and -Wshift-overflow).  GCC
should be consistent in handling all these and so all the others would need to
change as well.
5) There is an easy way to rewrite the code to avoid the warning:

  int too_large (long x)
  {
  #if INT_MAX < LONG_MAX   // or in GCC 7, INT_SIZE < LONG_SIZE
    return 32768 * 65536L < x;
  #else
    return 0;
  #endif
  }

Reply via email to