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