how to make gcc warn about arithmetic signed overflow
Brian Drummond
brian@shapes.demon.co.uk
Sat Sep 21 17:36:00 GMT 2013
On Sat, 2013-09-21 at 18:46 +0200, wempwer@gmail.com wrote:
> int ab = 50000;
> int bc = 50000;
> int r = ab * bc;
>
> Is it possible for gcc to produce a
> warning in such situation?
Yes, gcc the Gnu Compiler Collection can produce such a warning:
procedure test_ovf is
ab : integer := 50000;
bc : integer := 50000;
r : integer := ab * bc;
begin
null;
end test_ovf;
gcc -c test_ovf.adb
test_ovf.adb:4:22: warning: value not in range of type
"Standard.Integer"
test_ovf.adb:4:22: warning: "Constraint_Error" will be raised at run
time
However I'm not sure it is allowed to do the same with C.
- Brian
More information about the Gcc-help
mailing list