how to make gcc warn about arithmetic signed overflow

Dave Allured - NOAA Affiliate
Mon Sep 23 20:37:00 GMT 2013

On Mon, Sep 23, 2013 at 1:42 PM, Oleg Endo <> wrote:
> On Mon, 2013-09-23 at 13:38 -0600, Dave Allured - NOAA Affiliate wrote:
>> I believe the CPU overflow flag is updated after most integer
>> arithmetic instructions.  Does GCC have any facility for checking this
>> flag after each integer operation?  This would be a runtime check, of
>> course, not a compile time check.
> See -ftrapv option.  Although trapping math is not supported on every
> target properly.
> E.g.
> or SH related

Oleg, thanks for the tip.  "-ftrapv is seriously broken and nobody
wants to fix it", and that was 5.6 years ago.  Too bad, it seems like
a useful thing when you need it.  I use gcc's -ffpe-trap routinely to
guard fortran floating point stuff, and it has done many favors for


More information about the Gcc-help mailing list