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

--- Comment #11 from Martin Sebor <msebor at gcc dot gnu.org> ---
Right.  Because the call to __builtin_mul_overflow in the test case is not a
constant expression, the -Woverflow warning detects the overflow in the
multiplication subexpression that is constant.  The __builtin_mul_overflow call
is evaluated into a constant but not until after the warning has detected the
overflow.

The patch for bug 68120 introduced other built-ins to determine overflow at
compile-time.  Using those the return statement in this test case would look
something like this:

    return __builtin_mul_overflow_p (0x7fffffff, 0x7fffffff, 0)
           ? 2 : (0x7fffffff * 0x7fffffff == 0x7fffffff * 0x7fffffff);

and compile with no warning.

Reply via email to