This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/68971] -Woverflow false alarm in code unreachable after __builtin_mul_overflow
- From: "joseph at codesourcery dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 18 Dec 2015 00:28:26 +0000
- Subject: [Bug c/68971] -Woverflow false alarm in code unreachable after __builtin_mul_overflow
- Auto-submitted: auto-generated
- References: <bug-68971-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68971
--- Comment #2 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
On Thu, 17 Dec 2015, msebor at gcc dot gnu.org wrote:
> Paul, the way I prefer to look at it is that the C standard says that constant
> expressions are evaluated during translation and when the evaluation overflows
> the behavior is undefined. The program is incorrect and the warning helps find
> the bug. That GCC happens to handle it gracefully is a bonus.
There are several issues with the standard specification of constant
expressions, but my understanding is that all the requirements on constant
expressions apply where the syntax specifies that there is a constant
expression, not where some expression happens to have operands that are
constants but is used in a context not requiring a constant expression.
Thus, overflow in an expression of constants, where a constant expression
is not required, produces a warning rather than a pedwarn. Furthermore,
it seems clear that where a constant expression *is* required, unevaluated
subexpressions may contain overflows just as they may contain division by
zero (footnote 118).