[Bug c/126003] integer overflow during compile-time arithmetic is not always detected
foss+gcc@alejandro-colomar.es
gcc-bugzilla@gcc.gnu.org
Tue Jun 30 21:05:37 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126003
Alejandro Colomar <foss+gcc@alejandro-colomar.es> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jsm28 at gcc dot gnu.org
--- Comment #5 from Alejandro Colomar <foss+gcc@alejandro-colomar.es> ---
(In reply to Drea Pinski from comment #1)
> twogig+twogig is only undefined if executed.
> While TWOGIG+TWOGIG is considered as part of a constant integer expression
> so it need to warn there.
This is not correct. TL;DR: Both of them only have UB if executed, and none
of them violate any constraints. See below.
CC += Joseph
TWOGIG+TWOGIG, by being part of an argument to a function, is not a constant
expression.
According to Joseph, the response to issue 0261 is relevant here.
<https://www.open-std.org/jtc1/sc22/wg14/issues/c99/log.html#issue0261>
The response to that issue was:
In general, the interpretation of an expression for constantness is
context sensitive. For any expression which contains only constants:
* If the syntax or context only permits a constant expression, the
constraints of 6.6#3 and 6.6#4 shall apply.
* Otherwise, if the expression meets the requirements of 6.6 (including
any form accepted in accordance with 6.6#10), it is a constant
expression.
* Otherwise it is not a constant expression.
Thus, both TWOGIG+TWOGIG and twogig+twogig are regular expressions, and both
have UB. There is no constraint violation in that program.
More information about the Gcc-bugs
mailing list