Re: how to make gcc warn about arithmetic signed overflow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 21 Sep 2013, Jonathan Wakely wrote:

On 21 September 2013 17:46,  wrote:
Is it possible for gcc to produce a
warning in such situation?

If ab and bc are 'const' then G++ will warn:

o.cc: In function ‘int main()’:
o.cc:5:14: warning: integer overflow in expression [-Woverflow]
int r = ab * bc;
             ^

The C compiler still doesn't warn though, due to different rules for
how constants are handled between C and C++.

It does warn with -O though... (still only with const)

That's just the compiler not being good enough. I was going to mention -fsanitize=undefined for gcc-4.9 for a runtime warning, but it doesn't handle this yet, and -ftrapv never really worked.

--
Marc Glisse




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux