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

--- Comment #4 from Paul Eggert <eggert at gnu dot org> ---
(In reply to Martin Sebor from comment #1)
> constant expressions are evaluated during translation

This is not a constant expression. Not that that should matter. For example:

  enum { a = (1 ? 0 : 1 / 0) };
  enum { b = (1 ? 0 : 0x7fffffff * 0x7fffffff) };

Both integer constant expressions are valid C, and GCC (correctly) doesn't warn
about either of them.

> The program is incorrect and the warning helps find the bug.

No, the program has perfectly well-defined runtime behavior in GNU C because
the integer overflow is not evaluated. There is no bug here, and GCC's warning
is a false alarm.

This problem was occurring in gnulib, and we have worked around it in gnulib by
disabling -Woverflow in the affected translation unit. As a practical matter it
would be better if -Woverflow did not generate false alarms in cases like this,
as the false alarms will cause -Woverflow to be disabled in more places. Which
would be too bad, as __builtin_mul_overflow etc. are likely to be used in
programs where -Woverflow would otherwise be quite useful.

Reply via email to