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

--- Comment #11 from Martin Sebor <msebor at gcc dot gnu.org> ---
Yes, bug 4210 looks like a duplicate.   The test case from attachment 40722
recast in the context of that enhancement request looks like this:

  int too_large (long x)
  {
    const int b = sizeof (int) < sizeof (long)
    if (b)
      return 32768 * 65536L < x;
    return 0;
  }

An even less straightforward example might be one where b is an element of an
array initialized (or assigned to) from constants, or, for a type with more
than two values, in some set that excludes the tested value, or the result of a
function call with constant arguments expanded inline by the optimizer.  Etc. 
(Note that in all of these examples the warning is expected to do more than
what it's intended and documented to do, namely "warn about compile-time
overflow in constant expressions.")

Deferring the warning until later stages of optimization in an effort to expand
the set of contexts in which it recognizes that a constant expression cannot be
evaluated at runtime would quite likely come at the cost of a growing rate of
both false negatives and other false positives resulting from the very
transformations the smarter warning would have to depend on.

Reply via email to